Lab ^ | Unix Linux Forums | Homework & Coursework Questions

  Go Back    


Homework & Coursework Questions Students must use and complete the template provided. If you don't, your post may be deleted! Special homework rules apply here.

Lab ^

Homework & Coursework Questions


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-07-2013
herb bertz herb bertz is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 28 March 2013, 1:31 AM EDT
Posts: 9
Thanks: 1
Thanked 1 Time in 1 Post
Ubuntu Lab ^

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:
Filter a file for lines that have exactly 5 numbers in a row.


2. Relevant commands, code, scripts, algorithms:
Use the grep command with any options and wild cards.


3. The attempts at a solution (include all code and scripts):

Code:
 grep "[0-9]\{5\}" filterdata 
grep [0-9][0-9][0-9][0-9][0-9] filterdata
grep "[0-9]\{5,\}" filterdata
grep "[0-9]\{5\}" * filterdata
grep "[0-9]{5}" filterdata
grep "[0-9]\{5\}" . filterdata

(filterdata being the file Iam trying to Filter)


4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Owens Community College, Toledo, Ohio, Thomas McLeary, EET 208

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Last edited by Scrutinizer; 03-07-2013 at 08:30 AM.. Reason: code tags
Sponsored Links
    #2  
Old 03-07-2013
anbu23's Avatar
anbu23 anbu23 is offline Forum Advisor  
Advisor
 
Join Date: Mar 2006
Last Activity: 21 November 2014, 4:45 AM EST
Location: Bangalore,India
Posts: 2,091
Thanks: 12
Thanked 131 Times in 126 Posts

Code:
$ cat file
123456
12345
12345a dfdf
121
12345 dfd
$ grep -w "[0-9]\{5\}" file
12345
12345 dfd

The Following User Says Thank You to anbu23 For This Useful Post:
herb bertz (03-10-2013)
Sponsored Links
    #3  
Old 03-07-2013
Scrutinizer's Avatar
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 26 November 2014, 4:58 AM EST
Location: Amsterdam
Posts: 9,615
Thanks: 293
Thanked 2,452 Times in 2,200 Posts
Check out the ^ and $ anchors in regular expressions. Also it says "numbers", not "digits" . -w may work but is not a portable grep option.
    #4  
Old 03-07-2013
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 25 November 2014, 4:08 AM EST
Location: France
Posts: 2,930
Thanks: 81
Thanked 624 Times in 596 Posts
So if a line is like :


Code:
bla 12 34 890 56 78 bla bla

... it does have exactly 5 numbers in a row
Sponsored Links
    #5  
Old 03-07-2013
herb bertz herb bertz is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 28 March 2013, 1:31 AM EDT
Posts: 9
Thanks: 1
Thanked 1 Time in 1 Post
Thanks for the aid. Tried the grep -w "[0-9]\{5\} file with no luck. the numbers are consecutive (12345) and I need to show the complete line that they are in.
Sponsored Links
    #6  
Old 03-07-2013
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 25 November 2014, 4:08 AM EST
Location: France
Posts: 2,930
Thanks: 81
Thanked 624 Times in 596 Posts
The solution just depends on the way you understand the statement :


Code:
"Filter a file for lines that have exactly 5 numbers in a row"

1) do "numbers" stand for "digit" ?

2) what does "in a row" mean ? separated by a space ? other ?

3) does this means that the lines does have and only have 5 numbers in a row?

4) or may the line contain other non-numeric characters (may those "5 numbers in a row" be placed anywhere in the line) ?
Sponsored Links
    #7  
Old 03-07-2013
herb bertz herb bertz is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 28 March 2013, 1:31 AM EDT
Posts: 9
Thanks: 1
Thanked 1 Time in 1 Post
Lab example

this line has four 1234 numbers
this line has five 12345 numbers
this line has six 123456 numbers
this line has seven 1234567 numbers
this line has eight 12345678 numbers
part one of the lab is to just return the line with five numbers.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
help me with lab im new to bash.... elginmulizwa Shell Programming and Scripting 1 10-04-2011 01:07 AM
Help completing lab. ink Homework & Coursework Questions 4 09-29-2010 11:54 AM
cant complete lab ??? ink Shell Programming and Scripting 1 09-28-2010 06:52 PM
Shell Script Lab rktompsett Programming 1 04-27-2010 11:16 AM
VMWare Workstation for home lab vedder191 UNIX for Dummies Questions & Answers 0 08-27-2005 09:19 PM



All times are GMT -4. The time now is 07:09 AM.