![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | 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. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need to replace the first word of a line if it occurs again in the next line(shell) | geeko | Shell Programming and Scripting | 4 | 06-18-2009 03:36 PM |
| delete blank space in begining of line | karthikn7974 | Shell Programming and Scripting | 4 | 05-07-2008 05:40 AM |
| Read line by line not word by word | vadharah | Shell Programming and Scripting | 6 | 03-02-2008 02:29 PM |
| how to move word by word on command line | pbsrinivas | UNIX for Dummies Questions & Answers | 1 | 11-23-2007 06:17 AM |
| Can a shell script pull the first word (or nth word) off each line of a text file? | tricky | Shell Programming and Scripting | 5 | 08-17-2006 07:29 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 -n -e 's/.*\(ListenPort="[0-9][0-9][0-9][0-9][0-9]"\)$/\1/p' test.txt Input: ListenAddress="xyz.com" ListenPort="11111" Name="V1Server" NativeIOEnabled="true" <Machine Name="xyz"> <Manager ListenAddress="" ListenPort="11113" Name="xyz"/> </Machine> ListenAddress="xyz.com" ListenPort="11112" Machine="xyz" Name="V2Server" Expected output Output: ListenAddress="xyz.com" ListenPort="11111" Name="V1Server" NativeIOEnabled="true" <Machine Name="xyz"> <Manager ListenAddress="" ListenPort="11113" Name="xyz"/> </Machine> ListenAddress="xyz.com" ListenPort="11112" Machine="xyz" Name="V2Server" Thanks |
|
||||
|
Thanks for your reply
I still could not make it work due to syntax. Again, the pattern ListenAddress also appears in the middle of line which I dont want to tocuch it. awk '/ListenAddress=/{printf("%s\n%s ", $1, $2);next}$0{print}' File1 awk: syntax error near line 1 awk: bailing out near line 1 Thanks again |
|
||||
|
Quote:
Code:
awk '/^ListenAddress=/{printf("%s\n%s ", $1, $2);next}$0{print}' input
If you get errors, use gwk, nawk or /usr/xpg4/bin/awk on Solaris Regards |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|