How to reverse output?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to reverse output?
# 1  
Old 01-12-2009
How to reverse output?

hi,
I have to reverse the command output like below:
output:

online
offline
disable
maintening
killed

How to reverse this output like:

killed
maintening
disable
offline
online

It should be ksh script.

Thanks very much!
a2156z
# 2  
Old 01-12-2009

Some systems have a command, tac, that does what you want. If not, you can do it with:

Code:
awk '{ x = $0 "\n" x } END { printf "%s", x }'

# 3  
Old 01-12-2009
hi,
I have found a way to share, welcome more comments for it.
output | /usr/bin/tail -r
a2156z
# 4  
Old 01-12-2009
Code:
$ printf "%s\n" 1 2 3 4 | tail -r
tail: invalid option -- r
Try `tail --help' for more information.

# 5  
Old 01-12-2009
try this
printf "%s\n" 1 2 3 4 >temp
tail -r temp
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Reverse complement

I want to reverse some DNA sequences and complement them at the same time. Thus, A changes to T; C to G; T to A and G to C. example: infile >GHL8OVD01CMQVT SHORT1 TTGATGT >GHL8OVD01CMQVT SHORT2 TTGATGT outfile: >GHL8OVD01CMQVT SHORT1 ACATCAA >GHL8OVD01CMQVT SHORT2 ACATCAA The... (4 Replies)
Discussion started by: Xterra
4 Replies

2. Shell Programming and Scripting

Reverse even lines

I'm trying to reverse every even line in my file using the awk command below but it prints only the odd lines but nothing else: $ awk '(NR % 2) {print}; !(NR % 2) {print | "rev";}' myfile Any idea what I might have done wrong? Thank you. (10 Replies)
Discussion started by: ivpz
10 Replies

3. Shell Programming and Scripting

Reverse sort

Hello, I have a large list of names and would like to do a reverse sort on them i.e. the sort should be by the ending and not by the beginning of the word. I had written in awk a small script but it does wrong things { for(i=length($0);i>=1;i--) printf("%s/n",substr($0,i,1)); } Could anyone... (3 Replies)
Discussion started by: gimley
3 Replies

4. Shell Programming and Scripting

Reverse of a string

Hi All, I have a String str="Manish". I would like to reverse it. I know the option to do this in bash is: echo "Manish" | rev but I have seen an alternate solution somewhere, which states that: str="Manish" echo $str | awk '{ for(i=length($0);i>=1;i--) printf("%s",substr($0,i,1));... (7 Replies)
Discussion started by: manishdivs
7 Replies

5. Shell Programming and Scripting

Reverse the output using for loop

Good morning!! Im trying to ge tthe output in this for loop to be reversed. #!/usr/bin/perl $i = 1; for($i != 0 ; $i < 11 ; $i++){ print "$i\n"; } Ive tried changing the i++ to i--, but it makes the outputted numbers different also. Thanks bigben (4 Replies)
Discussion started by: bigben1220
4 Replies

6. Shell Programming and Scripting

how to reverse file

i am using AIX -ksh how can i reverse any file ,i have already try tac cmd it is not in AIX: please help me out. (3 Replies)
Discussion started by: RahulJoshi
3 Replies

7. Shell Programming and Scripting

Reverse lookup

hey guys, can anybody help me out here on the following: grep '^\{1,3\}\.\{1,3\}\.\{1,3\}\.\{1,3\}$' ravi.txt mary.txt lisa.txt https://www.unix.com/images/misc/progress.gif i.e what i did was found ip addreses from different files and then i want... (1 Reply)
Discussion started by: ravis83
1 Replies

8. Shell Programming and Scripting

reverse sort

Hello, How do i sort a csv file. i should be sorting column1(varchar),column2*(varchar) in ascending and column4 in descending order(numeric datatype). I tried few combinations of sort, but doesn't seem to be getting the right result. sort -t "," -k 1 -k 2 -k 4nr file any help is... (3 Replies)
Discussion started by: markjason
3 Replies

9. Linux

Reverse Proxy

I have configured reverse proxy through apache...conf file is attached My reverse proxy has a public ip.it is redirecting the request to 172.16.1.43 which is http server.....Now i have a link in Http server's home page which will redirect the request to another Lan zone machine... (0 Replies)
Discussion started by: dipanrc
0 Replies

10. Shell Programming and Scripting

Reverse *

when I do $ ls z* List of all files begining with 'z'. But what if I want to do a reverse lookup. Just for interest sake ;) $ ls ztr should be same as $ ls ztr* $ ls zt* $ ls z* (2 Replies)
Discussion started by: azmathshaikh
2 Replies
Login or Register to Ask a Question