![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
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 |
| run script with ./ in front of name | rig123 | Shell Programming and Scripting | 3 | 03-10-2006 04:58 AM |
| Appending columns on a file | abel | Shell Programming and Scripting | 2 | 09-27-2002 07:04 AM |
| Front end on Unix | shibz | UNIX for Advanced & Expert Users | 4 | 11-17-2001 12:37 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hi
consider this as the first line 00010015 MORGAN STANLEY & CO INCORPORATED N 110 INVESTAR 1 0001OT NJ 201-830-5055 01-Jan-1974 00:00:00 1 01-May-2008 00:00:00 05-Jun-2008 13:34:18 0001 - From SMSRun1_GIDQA02 Consider this as the second line 00010015 MORGAN STANLEY & CO INCORPORATED N 110 INVESTAR 1 0001OT NJ 201-830-5055 01-Jan-1974 00:00:00 1 01-May-2008 00:00:00 05-Jun-2008 13:34:18 0001 egesdegjeog rogjeogje - From SMSRun1_GIDQA02 Here i need to cut "- From SMSRun1_GIDQA02" from the end of each line and need to append it at the front as "From SMSRun1_GIDQA02 - ". So that the output looks like From SMSRun1_GIDQA02 - 00010015 MORGAN STANLEY & CO INCORPORATED N 110 INVESTAR 1 0001OT NJ 201-830-5055 01-Jan-1974 00:00:00 1 01-May-2008 00:00:00 05-Jun-2008 13:34:18 0001 But the problem here is that the position of "- From SMSRun1_GIDQA02" might vary from line to line since there might be odd number of columns.Can "- From" be taken as a key to cut "- From SMSRun1_GIDQA02" and append it to the front? Last edited by ragavhere; 07-08-2008 at 06:49 AM.. Reason: Line |
|
||||
|
Code:
sed 's/\(.*\)\( - \)\(.*\)/\3\2\1/' file > newfile The first portion is the begin of the string until the space before the last minus sign (before " - From"). The second portion are the 3 characters " - " before "From" and the last portion is the rest of the line. In the replacement string the portion is recalled in the order \3\2\1. Have a read of a sed tutorial, you can find some links here: Unix Tutorials/Programming Tutorials/Shell Scripting Tutorials Regards |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|