Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sed problem

Status
Not open for further replies.

sos

IS-IT--Management
Apr 10, 2000
53
CA
I have a log file with several lines in it like:

C:\WINDOWS\vb.ini:lkxups
C:\WINDOWS\vminst.log:pvgana
C:\WINDOWS\wiaservc.log:cxdqpj
C:\WINDOWS\wiaservc.log:eek:hcmgb

I'm trying to figure out a way using sed to chop off the second ':'and everything after it.

How can I tell sed to replace the second occurence of ':' ?
I know how to to do global search and replace but I'm not sure
how to tell sed to only find second instance of something.
 
man sed (the n flag of the s command)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Ok by s command do you mean 's/regexp/replacement/'. I don't see any reference to an "n flag" in the man page under this section. In fact there is no reference to "flag" anywhere in the man page for sed on my system.

I have been searching for a way to do this for like 2 weeks now. The only solution I have found is to remove the first ':' with 's/C://' then remove the second ':' and everything after it. Then I do 's/^/C:/'. This works but im sure there has to be an easier way to do it.
 

I am by no means a sed guru, I just get things to work:

#!/bin/sh
sed 's/:[a-z,A-Z,0-9]*//2' datafile

gene
 
You could just use cut

cut -d: -f 1,2 filename

where -d: is the delimiter char
where -f 1,2 = fields 1 & 2

Mike

"A foolproof method for sculpting an elephant: first, get a huge block of marble, then you chip away everything that doesn't look like an elephant."

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top