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

SED line delete - string at certain position help

Status
Not open for further replies.

AlStl

MIS
Oct 2, 2006
83
US
Hi,

I would like to remove all the lines in a file that contains letters (upper case) KJ at postions 6-7 from the begging on line.

an example would be:

1ABNPKJLDS9PORT_SIL 200708800 copu
1PORPKJLDUS9PORT_UYT 200700000 KLPU
1ABTPKJLDS9JOB_SIL 200708800 CPOI
1POIPKJLDUS9PO_UYT 200700000 YUTO
1ABTPTXLDS9JOB_SIL 200708800 CPOI
1POIPTXLDUS9PO_UYT 200700000 YUTO
1POIPMILDUS9PO_UYT 200700000 YUTO

Resulting file should only have:

1ABTPTXLDS9JOB_SIL 200708800 CPOI
1POIPTXLDUS9PO_UYT 200700000 YUTO
1POIPMILDUS9PO_UYT 200700000 YUTO

I am trying this, but its not working:

sed -i '/^.....KJ/d' file_name


Any help will be appreciated.

Al
 
My system (Solaris) chokes on the '-i', but other than that it's working as expected.

What results or errors are you getting?

 
Code:
sed -i '/^.{5}KJ/d' file

Works for me



Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Could you possibly have a control character, or other non-printing character that you can't see in there? Try this...

Code:
# Just chop off first five characters to see if your 'KJ's start with 'KJ'
sed '/^.....//g' file

# Look for non-displaying characters
od -c file

# Don't use sed
grep -v '^.....KJ' file

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top