The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-05-2006
ravi.sadani19 ravi.sadani19 is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 42
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
  #2 (permalink)  
Old 10-05-2006
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,209
Instead of trying to guess when your data actually looks like I would ask that you post a real sample ( multiple lines ) so that there is some possibility that a working solaution can be proposed.
  #3 (permalink)  
Old 10-05-2006
ravi.sadani19 ravi.sadani19 is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 42
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
  #4 (permalink)  
Old 10-05-2006
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,513
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)
Output:
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
  #5 (permalink)  
Old 10-05-2006
ravi.sadani19 ravi.sadani19 is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 42
Thanks,
But i looking a solution using unix shell script.Is it possible using sed command ??
  #6 (permalink)  
Old 10-05-2006
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,513
yes, definitely, but you got to wait for a while.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:46 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0