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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SED delete exact match

Status
Not open for further replies.

pavithra123

IS-IT--Management
Jun 17, 2001
54
CZ
In a file i have a line of numbers & I use SED to delete
the un-wanted lines, The problem is when I want to delete
00000000000000066666 these lines I use

/00000000000000066666/d in a file template and to delete

00000000000000006666 I use

/00000000000000006666/d In the same template file (16 zeros ), But by mistake if someone uses

14 zeros in the template file ie

/000000000000006666/d
, it deletes both the ones with 15 zeros and 16 zeros.

This is the normal behaviour of the SED, But I want to

to delete the exact line if it matches, I tried the exact
match expressions like

/0000000000000000\(6\{3\}\)/d

It does not seem to work any help will be greatly appreciated.

Pavithra
 
Not sure if I fully understood your requirements, but:

Are these 000000000000006666 at the beginning of the line?

If so, try this:
/^000000000000006666/d

If not so, you can perhaps make use of the character in front of 000000000000006666.

hope this helps

 
Unfortunately it is not at the start of the line, I just
want to delete the exact match whereever it is found on the
line.

Pavithra
 
ok, so two more questions:

What to you want to delete?
The string 000000000000006666,
or the whole line containing this string?

And what is in front of 000000000000006666,
is it always the same character perhaps?

(It might help if you could show part of your data,
current and desired.)
 
Hi Hoinz,

Sample data is below and its on one line, So its 3 lines

20000000096650417221700000000000000006666060223153634003C060223153640003C100C00248236975300120C0C0C001010100000000966505035999

20000000096650020058700000000000000066666051018103719003C051018103719003C100C00000000000001600C0COC001010100000000966505025999

20000000096650020058700000000000000066665051018103719003C051018103719003C100C00000000000001600C0COC001010100000000966505025999

I used ( 15 zeros )
00000000000000066666 and deltes the line perfecrtly no problems with that

00000000000000006666 ( 16 zeros ) and this deletes the
line with 6666 perfectly,

But when I use ( 14 zeros )
000000000000006666

then it deletes the 3 line as well, Which I do not want to delete.

I appreciate your help very much.

Pavithra
 
ok, if I understand correctly:
You want to delete a line with 14 consecutive '0', followed by 4 consecutive '6',
but you do not want to delete this line, if there are more then 14 '0', correct?

I think there is no way without some assumption on what is in front of these 14 '0';
we know that it must not be another '0';
may we assume that it is one of the numerals '1' to '9' ?

In this case grep may be your friend, try this:
grep -v [1-9]000000000000006666 old_file > new_file

or in case it may be a numeral or a capital letter:
grep -v [1-9,A-Z]000000000000006666 old_file > new_file

hope this helps
 
btw, this idea should work with sed too:
/[1-9]000000000000006666/d
 
HI Hoinz,

Thanks a lot for your suggesstions, Unfortunately I cannot use grep, I am alreadying using SED and its part of a script.

pavithra
 
Sorry,
your answer makes me a bit confused ....
[3eyes] [ponder]
Did you read my post from 23 Feb 06 10:45 ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top