Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Given an input file , reverse every two lines of the file and print the output.
- Ex:-
- Input file content --
- $ cat st.txt
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- Output --
- 2
- 1
- 4
- 3
- 6
- 5
- 8
- 7
- 10
- 9
- -----------------------------------------------------------
- Solution 1:- Using awk command
- awk '{if(NR%2==1) { line=$0 } else { print $0"\n"line }}' st.txt
- Solution 2:- Using sed command (looks elegant but complicated until you get your head around it)
- sed -n 'x;N;G;h;$p' st.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement