Using sed to print from the bottom up?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using sed to print from the bottom up?
# 1  
Old 11-17-2008
Using sed to print from the bottom up?

I have file.txt
Code:
bob
jon
jones
gary

I want to print from the botton, up using sed.

Code:
gary
jones
jon
bob

Whats one command I can use to do this? Or will I have to construct a new file that would hold the original file in reverse and then print the reversed file?
# 2  
Old 11-17-2008
Code:
sed -n '1{
h
}
1 !{
x
H
}
${
x
H
p
}' filename

# 3  
Old 11-17-2008
In linux you can do print file in reverse called tac ( cat in reverse mode ) Smilie).
No need to sed .. Smilie
Don't know about the other unices .
# 4  
Old 11-18-2008
Hi,

or this way:

Code:
sed -n '1!G;h;$p' file

HTH Chris
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to print from bottom to top?

Hi, i have a file which contains PID and wanted to execute kill command. but the thing is, when killing PID's needs to kill PID from bottom to top. Please help INPUT 21414 sh -c extract.ksh ASA 21416 /bin/ksh extract.ksh ASA 21428 /usr/bin/perl -w /var/tmp/tempperl.21416 ASA... (4 Replies)
Discussion started by: reignangel2003
4 Replies

2. Shell Programming and Scripting

Print n lines from top and n lines from bottom of all files with .log extenstion

Oracle Linux 6.4 In a directory I have more than 300 files with the extension .log I want the first 5 and last 5 lines of these .log files to be printed on screen with each file's name. Expected output : Printing first 5 and last 5 lines of FX_WT_Feb8_2014.log !! Authentication... (7 Replies)
Discussion started by: kraljic
7 Replies

3. UNIX for Dummies Questions & Answers

Take the 2nd line from the bottom

Dear friendly helpers, I want to compare the last line and the 2.nd line from the bottom later with a calculation. The rest of the script is working. What is wrong with my solution? I want to take the 2nd line from the bottom. And I do not know the command. TAIL -2 is wrong because it takes... (2 Replies)
Discussion started by: Pieter0815
2 Replies

4. What is on Your Mind?

Should We Keep or Drop the Bottom Toolbar?

Well, it's been a few months now since we started running the toolbar on the bottom with some navigation menu, search, link to code tag video, some social networking tools, etc. So, the question of the day is: Should we keep it, maybe develop more toolbar apps, or dump it? Please vote ... (13 Replies)
Discussion started by: Neo
13 Replies

5. Shell Programming and Scripting

Search for string and print top and bottom line

Hi Folks I need a one liner to parse through a log and if the string is found print the line above, the line with the string and the line below. example: The ball is green and blue Billy through the ball higer. Jane got hurt with the ball. So if I search for Billy I would need the 3... (1 Reply)
Discussion started by: bombcan
1 Replies

6. Shell Programming and Scripting

Menu at the bottom

Hi everyone, I'm new to Linux and bash scripting. Question? How can I display a menu at the bottom of the screen when displaying a content of a file with the less command? Like in gvim with bash support, when debugging or testing your script this text "Press enter or type command to... (0 Replies)
Discussion started by: Qwond
0 Replies
Login or Register to Ask a Question