![]() |
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 |
| help needed | nnayagam | Shell Programming and Scripting | 2 | 03-07-2008 06:34 AM |
| Little help needed. | Netghost | AIX | 5 | 08-10-2006 02:29 PM |
| Help needed | dsravan | Shell Programming and Scripting | 2 | 07-20-2006 09:37 AM |
| awk help needed. | cskumar | Shell Programming and Scripting | 0 | 07-20-2006 07:24 AM |
| Sed help needed | stevefox | Shell Programming and Scripting | 5 | 12-05-2005 01:44 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Help Needed -sed
Hi All,
i have one file and in that i have to read each line and do some replacement. its is not fixed the number or column always be same it can be less also exm a;b;c;d;e;f (line) i have to do something like In the line If c is present then go to end of line and append ';date' else go to end of line and append ';;date' i am trying with sed command . but not actually gettin how to implement. Kindly help me |
|
||||
|
RE- Hope this will help to understant clearly
input
121212;mrkt;share;UUU;SDS;C 121213;sales:trade;IMM;SSS;B;Cat;2222 121214;admin;books;CCC;DDD;D look for Cat if present then append ;date at end of line else append ;;;date at end of line output 121212;mrkt;share;UUU;SDS;C;;;06102006 121213;sales:trade;IMM;SSS;B;Cat;2222;06102006 121214;admin;books;CCC;DDD;D;;;06102006 |
|
||||
|
Python Alternative:
Code:
import time
thedate = time.strftime("%d%m%Y",time.localtime())
for lines in open("input.txt"):
lines = lines.strip() #strip new lines
if 'Cat' in lines:
print "%s;%s" %(lines,thedate)
else:
print "%s;;;%s" %(lines,thedate)
Code:
/home> python test.py 121212;mrkt;share;UUU;SDS;C;;;06102006 121213;sales:trade;IMM;SSS;B;Cat;2222;06102006 121214;admin;books;CCC;DDD;D;;;06102006 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|