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

sed command not working

Status
Not open for further replies.

aliyesam

Technical User
Sep 27, 2018
1
0
0
US
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
 
Hi

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

What I would try :
[ul]
[li]
Code:
sed -E '/^[0-9]\{8\}\(0[1357]\|1[01]\)/d' a.txt
[/li]
[li]
Code:
sed -E '/^[0-9]{8}(0[1357]|1[01])/d' a.txt
[/li]
[li]
Code:
sed -r '/^[0-9]{8}(0[1357]|1[01])/d' a.txt
[/li]
[li]
Code:
sed '/^[0-9]\{8\}0[1357]/d;/^[0-9]\{8\}1[01]/d' a.txt
[/li]
[/ul]

BTW, your code works fine as it is with GNU [tt]sed[/tt] 4.4.


Feherke.
feherke.github.io
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top