×
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!
  • Students Click Here

*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.

Students Click Here

Jobs

sed command not working

sed command not working

sed command not working

(OP)
i want sed to only output lines that do not have "01","03","05","07","10","11" on the 9th and 10th position
e.g look at the file below
I want only the three records from this file that have "33" ,"17" and "00" at 9th and 10th position.
433483433339
167710001710
167730600000

operating system is sun solaris and Linux .

oracle:$ sed '/^[0-9]\{8\}\(0[1357]\|1[01]\)/d' a.txt
000000001000
433483433339 <<< want this to be spitted out by sed 33 at 9th n 10th pos
121121211100
167710001710 <<< want this to be spitted out by sed 17 at 9th and 10th pos
167735250310
167735260510
167735280710
167735301010
167735431010
167735451010
167710101110
167730691110
167730600000 <<< want this to be spitted out by sed 00 at 9th and 10th pos

RE: sed command not working

Hi

I think your sed may use BRE ( Basic Regular Expression ), while the | is ERE ( Extended Regular Expression ), at least according to The Open Group Base Specifications.

What I would try :
  • CODE

    sed -E '/^[0-9]\{8\}\(0[1357]\|1[01]\)/d' a.txt 
  • CODE

    sed -E '/^[0-9]{8}(0[1357]|1[01])/d' a.txt 
  • CODE

    sed -r '/^[0-9]{8}(0[1357]|1[01])/d' a.txt 
  • CODE

    sed '/^[0-9]\{8\}0[1357]/d;/^[0-9]\{8\}1[01]/d' a.txt 
BTW, your code works fine as it is with GNU sed 4.4.

Feherke.
feherke.github.io

RE: sed command not working

Why not the following. His requirements don't say that the file name is numeric, only that position 9-10 be one of 00,17, or 33

sed -E '/^.{8}(?:33|17|00)/d' a.txt

Bill
Lead Application Developer
New York State, USA

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! Already a Member? Login

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