INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

SED line delete - string at certain position help

SED line delete - string at certain position help

(OP)
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

RE: SED line delete - string at certain position help

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

What results or errors are you getting?

RE: SED line delete - string at certain position help

CODE --> shell

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

RE: SED line delete - string at certain position help

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 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close