sed pattern fails to delete line of numbers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed pattern fails to delete line of numbers
# 1  
Old 07-31-2013
sed pattern fails to delete line of numbers

We are using Red Hat Linux.

I have a flat file with among other things, the following lines, which appear occasionally throughout the file:

Using sed, I delete this line:

L;L;L;L;R;R;R;L;R;L;R;R;R;L;L;L

With:

/^[L|R];[L|R];[L|R];[L|R];[L|R];[L|R]*/d

Works fine every time.

However, I cannot delete this line:

5;8;4;22;15;9;23;6;12;7;12;12;12

I have tried the following patterns, none of which seems to work:

/^[0-9][0-9]?;[0-9][0-9]?;[0-9][0-9]?;[0-9][0-9]?;[0-9][0-9]?;[0-9][0-9]?*/d


/^[0-9]?;[0-9]?;[0-9]?;[0-9]?;[0-9]?;[0-9]?*/d


/^[0-9].?;[0-9].?;[0-9].?;[0-9].?;[0-9].?;[0-9].?*/d

/^[0-99];[0-99];[0-99];[0-99];[0-99];[0-99];[0-99]*/d

Can anyone help me?

Thanks,

bloomlock
# 2  
Old 07-31-2013
may be sth like this...

Code:
awk '!/[0-9];[0-9];[0-9];[0-9][0-9];[0-9][0-9];[0-9];[0-9][0-9];[0-9];[0-9][0-9];[0-9];[0-9][0-9];[0-9][0-9];[0-9][0-9]/' file

# 3  
Old 07-31-2013
Code:
$
$ cat f90
Line 1
L;L;L;L;R;R;R;L;R;L;R;R;R;L;L;L
Line 3
5;8;4;22;15;9;23;6;12;7;12;12;12
Line 5
$
$
$ sed '/^\(L\|[0-9]\)\(;[LR0-9]\)\+/d' f90
Line 1
Line 3
Line 5
$
$

# 4  
Old 07-31-2013
pamu and durden,

Thanks for the quick replys, but unfortunately, they didn't work. Perhaps I should point out that the numbers between the semi-colons can be randomly one-digit or two-digit numbers.

The 'L;R;' etc and numbers are on different lines.

I have several sed commands in a file. All the others work. Just not the one for the numbers line.
# 5  
Old 07-31-2013
Code:
sed '/^\([LR];\)\{6,\}/ d' file
sed '/^\([0-9][0-9]*;\)\{6,\}/ d' file
sed '/^\([0-9]\{1,2\};\)\{6,\}/ d' file

And both (GNU sed only) including a mixture of digits and L/R:
Code:
sed '/^\([0-9]\{1,2\};\|[LR];\)\{6,\}/ d' file

Without a mixture it's simply two commands:
Code:
sed '/^\([0-9]\{1,2\};\)\{6,\}/ d; /^\([LR];\)\{6,\}/ d' file


Last edited by MadeInGermany; 07-31-2013 at 01:01 PM..
This User Gave Thanks to MadeInGermany For This Post:
# 6  
Old 07-31-2013
MadeInGermany!

Das geht! Ich habe Gluck gehabt mit: sed '/^\([0-9][0-9]*;\)\{6,\}/ d' file

Vielen Dank!

Tschuess!

bloomlock

---------- Post updated at 12:24 PM ---------- Previous update was at 12:08 PM ----------

Thank you very much for the assist!
# 7  
Old 07-31-2013
Quote:
Originally Posted by bloomlock

However, I cannot delete this line:

5;8;4;22;15;9;23;6;12;7;12;12;12

I have tried the following patterns, none of which seems to work:

/^[0-9][0-9]?;[0-9][0-9]?;[0-9][0-9]?;[0-9][0-9]?;[0-9][0-9]?;[0-9][0-9]?*/d


/^[0-9]?;[0-9]?;[0-9]?;[0-9]?;[0-9]?;[0-9]?*/d


/^[0-9].?;[0-9].?;[0-9].?;[0-9].?;[0-9].?;[0-9].?*/d

/^[0-99];[0-99];[0-99];[0-99];[0-99];[0-99];[0-99]*/d

Can anyone help me?
The basic regular expressions which sed uses by default do not specially consider the question mark to mean that its antecedent is optional; instead, the question mark is a literal question mark.

[0-9] and [0-99] are functionally identical, since bracket expressions and range expression endpoints are characters.

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sed. Delete line before and after pattern.

Hi. In need to delete line before and after pattern in file. I came to following commands. Delete line before sed -ni '/pattern/{x;d;};1h;1!{x;p;};${x;p;}' /etc/testfile Delete line after sed -i '/pattern/{N;s/\n.*//;}' /etc/testfile Is it possible to merge it in single command? (3 Replies)
Discussion started by: urello
3 Replies

2. Shell Programming and Scripting

Use sed to delete remainder of line after pattern

Greetings, I need some assistance here as I cannot get a sed line to work properly for me. I have the following list: Camp.S01E04.720p.HDTV.X264-DIMENSION Royal.Pains.S05E07.720p.HDTV.x264-IMMERSE Whose.Line.is.it.Anyway.US.S09E05.720p.HDTV.x264-BAJSKORV What I would like to accomplish is to... (3 Replies)
Discussion started by: choard
3 Replies

3. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

4. Homework & Coursework Questions

sed Multiple Pattern search and delete the line

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I have file which has got the following content sam 123 LD 41 sam 234 kp sam LD 41 kam pu sam LD 61 Now... (1 Reply)
Discussion started by: muchyog
1 Replies

5. Shell Programming and Scripting

sed pattern to delete lines containing a pattern, except the first occurance

Hello sed gurus. I am using ksh on Sun and have a file created by concatenating several other files. All files contain header rows. I just need to keep the first occurrence and remove all other header rows. header for file 1111 2222 3333 header for file 1111 2222 3333 header for file... (8 Replies)
Discussion started by: gary_w
8 Replies

6. Shell Programming and Scripting

sed to find pattern and delete line before and after

I have the following file: line1 line2 MATCH line3 line4 I need to find the pattern, "MATCH" and delete the line before and after MATCH. So the result should be line1 MATCH lline4 I have to use sed because it is the only utility that is common across my environments. I... (1 Reply)
Discussion started by: craftereric
1 Replies

7. Shell Programming and Scripting

sed find matching pattern delete next line

trying to use sed in finding a matching pattern in a file then deleting the next line only .. pattern --> <ad-content> I tried this but it results are not what I wish sed '/<ad-content>/{N;d;}' akv.xml > akv5.xml ex, <Celebrant2First>Mickey</Celebrant2First> <ad-content> Minnie... (2 Replies)
Discussion started by: aveitas
2 Replies

8. Shell Programming and Scripting

comment/delete a particular pattern starting from second line of the matching pattern

Hi, I have file 1.txt with following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433 ** ** ** In file 2.txt I have the following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433... (4 Replies)
Discussion started by: imas
4 Replies

9. UNIX for Advanced & Expert Users

Urgent Help required : awk/sed help to find pattern and delete till end of line

Hi, I need help with using an awk or sed filter on the below line ALTER TABLE "ACCOUNT" ADD CONSTRAINT "ACCOUNT_PK" PRIMARY KEY ("ACCT_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "WMC_DATA" LOGGING ENABLE Look for... (1 Reply)
Discussion started by: rajan_san
1 Replies

10. Shell Programming and Scripting

Urgent! Sed/Awk Filter Find Pattern Delete Till End Of Line

Hi, I need help with using an awk or sed filter on the below line ALTER TABLE "ACCOUNT" ADD CONSTRAINT "ACCOUNT_PK" PRIMARY KEY ("ACCT_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "WMC_DATA" LOGGING ENABLE Look for... (2 Replies)
Discussion started by: rajan_san
2 Replies
Login or Register to Ask a Question