Use sed to move last line to top


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Use sed to move last line to top
# 1  
Old 01-24-2010
Use sed to move last line to top

I have parsed a curl download with sed commands. I would also like to move the last line in the output file to the top. Can I use sed for this?
# 2  
Old 01-24-2010
How about:
Code:
sed '1h;1d;$!H;$!d;G' infile

# 3  
Old 01-24-2010
That works perfectly, thanks!
# 4  
Old 01-24-2010
By awk:

Code:
awk '{a[NR]=$0} END {print a[NR]; for (i=1;i<NR;i++) print a[i]}' urfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Move a line to top of the file

Hi, I have a following file and it has only one occurrence of line that says "Output view:". It could be in middle somewhere ( i don't know the exact location ). I want to move it as the first line of the file. Input AAA BBBB CCCC Output view: XXXX YYYY ZZZZ Output should be: Output... (13 Replies)
Discussion started by: jakSun8
13 Replies

2. Shell Programming and Scripting

sed: how to move matched pattern to end of previous line

Hello, I'm new to this forum. I've been doing a lot of sed work lately and have found many useful tips on this forum. I've hit a roadblock in a project, though, and could really use some help. I have a text file with many lines like the following, i.e., some lines begin with a single word... (3 Replies)
Discussion started by: paroikoi
3 Replies

3. Shell Programming and Scripting

Move lines above a line onto one line

So say I have the file: john london 24 male ======== jane london 22 female ======== mike 23 ======== Bob how do i get the information i need on one line as such: (5 Replies)
Discussion started by: linuxkid
5 Replies

4. Shell Programming and Scripting

awk script to move a line after the matched pattern line

I have the following text format in a file which lists the question first and then 5 choices after that the explanantion and finally the answer. 1.The amount of time it takes for most of a worker’s occupational knowledge and skills to become obsolete has been declining because of the... (2 Replies)
Discussion started by: nanchil_guy
2 Replies

5. Shell Programming and Scripting

append a line into a file in the top

hi, My code is #!/bin/sh echo "\n\nPlease enter the month of the year(YYYYMM) : \c" read date_rep INPUT_L9_FILE=L9_Recharge_Description_EOM_$date_rep.csv #This part is used to summarise Grand_Total, Balance_Total of file L9_Recharge_Description_EOM_${1}.csv. awk -F"," '{if(NR!=1)... (5 Replies)
Discussion started by: madfox
5 Replies

6. Shell Programming and Scripting

getting everything other that the top line

Hi there if I use `head -1` it gives me the top line .... is there a utility out there that will give me everything other than the top line ? I know how to achieve this by taking the file out to another file etc, but id like to be able to do it without creating additional files is this... (5 Replies)
Discussion started by: hcclnoodles
5 Replies

7. Shell Programming and Scripting

best way to insert a line at the top of a file?

say I want to insert "this is a test" as the first line into file A, besides echo "this is a test" > /tmp/tmpfile cat /tmp/tmpfile fileA >> /tmp/result, is there any simple way I can do it? thanks (7 Replies)
Discussion started by: fedora
7 Replies

8. Shell Programming and Scripting

find top 100 files and move them

i have some 1000 files in my dir and i want to find top 100 files and move them to some other location: below the 2 commands i used, but it is not working ls -ltr | grep ^- | head -100 | xargs mv destination - _________>not working ls -ltr | grep ^- | head -100 | xargs mv {}... (3 Replies)
Discussion started by: ali560045
3 Replies

9. Shell Programming and Scripting

move the last word to begining of next line - SED

Hello, I'm trying to move the last word of matching pattern to the begining of next line. Appreciate if anyone post the script. From the below line I'm getting the last word, Note: this word also appears in many places in my file #return the last word of line that contains ListenPort sed... (4 Replies)
Discussion started by: baskar
4 Replies

10. Shell Programming and Scripting

SED- Insert text at top of file

Does anyone know how to insert text at the top and bottom of a file using sed? (12 Replies)
Discussion started by: MBGPS
12 Replies
Login or Register to Ask a Question