sed command that deletes lines with 3-5 digit strings


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers sed command that deletes lines with 3-5 digit strings
# 1  
Old 12-08-2014
Error sed command that deletes lines with 3-5 digit strings

Hello!

My final exam in my Linux class is tomorrow, and I was just reviewing the grep and sed commands. I came across an example, by which I got stumped: it asks to provide a sed command that deletes all lines that contain exactly 3 to 5 digit strings, from a file.
In this case, I created a file that looks like this:

Line 1
Line 22
Line 333
Line 4444
Line 55555
Line 666666

So this sed command should print out only:

Line 1
Line 22
Line 666666

I tried the following command: sed '/[0-9]{3,5}/d' Lines.txt
but it doesn't do anything....

Could anyone please tell me my mistake?
THANK YOU!! Smilie
# 2  
Old 12-08-2014
Hi,

You need to match the space also.
Try this

Code:
 sed -r '/\s[0-9]{3,5}$/d' file.txt

# 3  
Old 12-08-2014
Ohhh, I didn't realize I have to match the space too! Now I know!

Thank You so much for helping me out!! Smilie
# 4  
Old 12-08-2014
Moderator's Comments:
Mod Comment Nila,
There is a special forum for homework assignments. Please do not respond to homework assignments posted to the regular forums.

And, when responding to posts in the Homework and Classwork forum, guide the submitter towards the answer; don't just do their homework for them.

This forum is not a tool to be used by students who want to get other people to do their homework for them.

Users submitting homework questions to the regular forums and users doing homework for students can both receive infractions. Repeated infractions can lead to being banned from this site.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to remove lines that do not start with digit and combine line or lines

I have been searching and trying to come up with an awk that will perform the following on a converted text file (original is a pdf). 1. Since the first two lines are (begin with) text they are removed 2. if $1 is a number then all text is merged (combined) into one line until the next... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

Script that takes IP address as an Input and deletes 7 lines

I have a flat file that contains a list of IP address following 6 additional lines. I would like to get a help in the following. a shell script that would take ip address or list of ip addresses as input, search one by one the ip address in the file and as soon as it find the exact match it... (12 Replies)
Discussion started by: knijjar
12 Replies

3. Shell Programming and Scripting

Print lines between two strings multiple occurencies (with sed, awk, or grep)

Hello, I can extract lines in a file, between two strings but only one time. If there are multiple occurencies, my command show only one block. Example, monfichier.txt contains : debut_sect texte L1 texte L2 texte L3 texte L4 fin_sect donnees inutiles 1 donnees inutiles 2 ... (8 Replies)
Discussion started by: theclem35
8 Replies

4. Shell Programming and Scripting

Sed or Awk for lines between two strings multiple times and keep the last one

Hi, I am trying to get lines between the last occurrences of two patterns. I have files that have several occurrences of “Standard” and “Visual”. I will like to get the lines between “Standard” and “Visual” but I only want to retain only the last one e.g. Standard Some words Some words Some... (4 Replies)
Discussion started by: damanidada
4 Replies

5. UNIX for Dummies Questions & Answers

Command rm deletes filename but not the blocks

Hi It happens when I try to delete a file of 250MB with the command rm -r on our old Intergraph CLIX that the filename disappears while the blocks remain on the machine. Only when I reboot the system the blocks really disappear. Then rm works again for sometime but after some time it happens... (15 Replies)
Discussion started by: hausi2012
15 Replies

6. Shell Programming and Scripting

Why sed command deletes last line in a file if no carriage return?

Hi I am using sed command to make SCORE=somevalue to SCORE=blank in a file. Please see the attached lastline.txt file. After executing the below command on the file, it removes the last line. cat lastline.txt | sed 's/SCORE=.*$/SCORE=/g' > newfile.txt Why does sed command remove the... (3 Replies)
Discussion started by: ashok.k
3 Replies

7. Shell Programming and Scripting

Place digit in front of the line searching pattern using sed command

hi All, i want to add the single digit front of the line in the report file and string compare with pattern file. patter file: pattern1.txt pattern num like 4 love 3 john 2 report file: report.txt i like very much but john is good boy i will love u so after execute... (9 Replies)
Discussion started by: krbala1985
9 Replies

8. Shell Programming and Scripting

How to get lines started with matched strings using sed or grep for loop?

I have a huge file and want to separate it into several subsets. The file looks like: C1 C2 C3 C4 ... (variable names) 1 .... 2 .... 3 .... : 22 .... 23 .... I want to separate the huge file using the column 1, which has numbers from 1 to 23 (but there are different amount of... (8 Replies)
Discussion started by: AMBER
8 Replies

9. Shell Programming and Scripting

Shell Program which deletes all lines ...

Shell Program which deletes all lines containing the word "UNIX" in the files supplied as argument..please help me to do this task :) (4 Replies)
Discussion started by: abhiseknitd
4 Replies

10. Shell Programming and Scripting

Replace one digit by two digit using sed

Folks, Is there a simple way to replace one digit by two digit using sed. Example, mydigit1918_2006_8_8_lag1.csv should be mydigit1918_2006_08_08_lag01.csv. I tried this way, but doesn't work. echo mydigit1989_2006_8_8_lag1.csv|sed 's/]/0]/' Thank you, (5 Replies)
Discussion started by: Jae
5 Replies
Login or Register to Ask a Question