![]() |
|
|
grep unix.com with google
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Our Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
How to change a file's content by row?
Greetings. So the question is basically the same as it's in the title. I'd like to write a program that changes a file by rows. So to clarify it. (i know i shouldn't use code,/code here but i would like to separate it) So for example a text file looks like something like this: Code:
Happy Birthday! Happy Mother's day! Happy New Year! . . . Happy Blablabla! and the result should look like: Code:
Happy Blablabla! . . . Happy New Year! Happy Mother's day! Happy Birthday! Sorry for this stupid example, but I think it is easier to understand in this way. The reason why i post this is that i've got no idea how to start it. I've searched for some commands that might switch the lines but found nothing. Thanks for your help in advance and sorry for my english, might have spelled something wrong! |
|
|||
|
Try tac command if you are on Linux. or Try: Code:
awk '!(A[i++]=$0); END { while(i--) print A[i] }' file
Last edited by dennis.jacob; 11-30-2009 at 07:37 AM.. Reason: removed the unnecessary use of {} |
| Bits Awarded / Charged to dennis.jacob for this Post | |||
| Date | User | Comment | Amount |
| 11-30-2009 | rdcwayx | nice solution | 100 |
|
|||
|
Quote:
Code:
awk '{A[i++]=$0} END { while(i--) print A[i] }' urfile
learn from dennis.jacob by using NR. Code:
awk '{A[NR]=$0} END {NR++; while (NR--) print A[NR]}' urfile
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| change field content awk | littleboyblu | Shell Programming and Scripting | 2 | 02-03-2009 11:57 PM |
| Change a file's timestamp | shibajighosh | AIX | 6 | 05-27-2008 02:26 PM |
| how to change the content thru sed..... | manas_ranjan | Shell Programming and Scripting | 3 | 09-22-2007 06:13 AM |
| Mass Change content in all files | terala | Shell Programming and Scripting | 1 | 11-20-2005 01:30 AM |
| checking file's permissions and change them | K-ONE | Shell Programming and Scripting | 7 | 04-10-2005 10:09 AM |