|
Author |
Message |
|
|
Posted May 04, 2008 at 8:49:38 PM
Subject: In a text file how do you move 3 lines down by 2 lines?
Hi,
I am doing a online linux course. I need to answer some question in this course.
Currently having problem with the following question:
Q: In a text file how do you move 3 lines down by 2 lines?
Can anyone help me to answer this question?
(answer should be some sorts of command)
|
Shashank Sharma
Joined Jan 01, 1970 Posts: 1657
Location:New Delhi, India
Other Topics
|
Posted:
May 06, 2008 3:48:08 PM
Subject: In a text file how do you move 3 lines down by 2 lines?
Well beats the purpose of the course/exam if we tell you, right? Besides, you didn't mention what text editor you're using, or, what editor does the question mention? Is it vi, emacs...?
You should read the man page of whatever text editor it is and you'll find the answer.
Coauthor of Beginning Fedora: From Novice to Professional published by Apress.
Please follow the Forum Guidelines
|
AR
Joined May 06, 2008 Posts: 22
Other Topics
|
Posted:
May 06, 2008 3:53:05 PM
Subject: In a text file how do you move 3 lines down by 2 lines?
I'm assuming you'd want to move the first three lines in a text file below the 4th and 5th so essentially this
1
2
3
4
5
becomes like:
4
5
1
2
3
In vi you can press the following keys (while standing on the first one): Vjjxjp
awk: awk 'NR<4{l[NR]=$0};NR>3{print};NR==5{print l[1]"\n"l[2]"\n"l[3]}'
example:
$ echo -e '1\n2\n3\n4\n5\n6\n7\n8' | awk 'NR<4{l[NR]=$0};NR>3{print};NR==5{print l[1]"\n"l[2]"\n"l[3]}'
4
5
1
2
3
6
7
8
I'm sure there is a way to do this in sed, too :)
|