How to implement this?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to implement this?
# 1  
Old 10-20-2010
How to implement this?

hi

i have a file like
Code:
1,"A","B"
2,"C","D"
1,"E","F"
3,"G","H"

in output i need like

Code:
3,"G","H"
1,"E","F"
2,"C","D"
1,"A","B"

that is what ever records in my file i need to reverse the order of rows as in the input. please give any pointers to this logic
regards
angel
# 2  
Old 10-20-2010
Try:
Code:
tac infile

# 3  
Old 10-20-2010
thanku so muchh SmilieSmilieSmilieSmilieSmilieSmilieSmilie


worked wellll
# 4  
Old 10-20-2010
If tac is not available, one method is to keep the lines in memory in reverse order and then print them at the last line. For example:

Code:
awk '{p=$0 RS p} END{printf "%s",p}' infile

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


Last edited by Scrutinizer; 10-20-2010 at 06:43 AM..
# 5  
Old 10-20-2010
tac is working fine .but i will try the above code also Smilie
# 6  
Old 10-20-2010
@Scrutinizer

Pls explain this part {p=$0 RS p} and how the lines are stored in the awk memory..
# 7  
Old 10-20-2010
p is a variable. RS="\n". On the first line p becomes the firs line followed by a "\n". Every next line gets put at the beginning of p with a "\n" in between. At the end the variable p is printed except for the superfluous trailing "\n" that was put there on line 1.

We could also keep the newline out of the string on line 1, for example
Code:
awk '{p=$0((p)?RS p:x)} END{print p}' infile

where x has the value ""
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Implement ps command in C

Hello, could anybody explain how the ps command works? I know something about the proc file system. But I'm still not sure about how it exactly works. Like ps without any option will print out the current user's processes, but it never displays my web browsers such as firefox or my LibreOffice... (3 Replies)
Discussion started by: freedombird9
3 Replies

2. Shell Programming and Scripting

How to implement scenario?

hi, i am having three files which is having following data file1: field1 field2 field3 1 A B 2 C D 3 E F file2: 4 G H 1 I J 5 K L file3: 4 M N (3 Replies)
Discussion started by: angel12345
3 Replies

3. Solaris

new - How i can implement Mirroring

Unix is something new for me, I trying learn about it now. I have download the sun virtualbox software and install solaris 10 into it. It is is like wizard with step by step installation guideline. :) NOw how can i implement mirroring(RAID) into the my new SunOS? can anyone give a briefly list... (14 Replies)
Discussion started by: webster5u
14 Replies

4. Shell Programming and Scripting

Trying to implement 'more' command

Hi all, i'm quite new in the UNIX world. So maybe i'm going to ask simple questions but they are unsolvable for me... I'm trying to implement the 'more' function or kinda of that, for improving my knowledges. But I encountered some problems that i hope u will help me to solve. The code i... (0 Replies)
Discussion started by: Cellofan
0 Replies

5. Shell Programming and Scripting

Trying to implement case

Hi All, My requirement is if the record is starting with 0, then do some processing. if starting with 1, some processing else (not with 0 or 1 ) then do some other processing. i tried the following case "$test" in /^0/) echo "starting with zero ;; /^1/) echo " with one" ;; *) echo... (3 Replies)
Discussion started by: ssunda6
3 Replies

6. Shell Programming and Scripting

Trying to implement case

Hi All, My requirement is if the record is starting with 0, then do some processing. if starting with 1, some processing else (not with 0 or 1 ) then do some other processing. i tried the following case "$test" in /^0/) echo "starting with zero ;; /^1/) echo " with one" ;; *) echo... (2 Replies)
Discussion started by: ssunda6
2 Replies

7. Shell Programming and Scripting

how to implement this

Hi all, could any of you please help me on my problem.. we are doing FTP (one report out put) from one server to another server through unix shell script program. Due to the network issues, some times FTP process is hanging. So we planned to modify the existing program with the following... (2 Replies)
Discussion started by: kishore_jasthi
2 Replies

8. Programming

how does va_arg implement ?

1 . How does va_arg implemented by system? (2 Replies)
Discussion started by: chenhao_no1
2 Replies

9. UNIX for Advanced & Expert Users

how can i implement rlogin

how can i use a rlogin with out entered a password, someone tell me about configure the next files /.rhosts /etc/hosts.equiv and /etc/hosts but i not sure about that, or there are not enough could you tell me how to do that? (3 Replies)
Discussion started by: jav_v
3 Replies

10. UNIX for Dummies Questions & Answers

how to implement diff

Hi Does someone know how Unix or Linux implement 'diff' command ? Any good reference or the algorithm will be better ? Thanks (3 Replies)
Discussion started by: harrylong
3 Replies
Login or Register to Ask a Question