Student needs grep command assistance


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Student needs grep command assistance
# 1  
Old 11-23-2017
Student needs grep command assistance

I am a student in a UNIX/Linux classes having hard time with grep looking for assistance on some home work

I need to figure out some kind of grep command to get a out put that only gives me information from a sample file and only list the people with the first name John the sample file is named smallFile and contains information like

John:Doe:ECE:3.54:doe@jd.home.org:111.222.3333
James:Davis:ECE:3.71:davis@jd.work.org:111.222.1111
John:Clark:ECE:2.68:clark@xyz.ab.com:111.111.5555
John:Lee:EE:2.64:jlee@j.lee.com:111.111.2222
Lu:John:CS:3.06:lu.john@xyz.org:111.333.1111
Adam:Giles:SS:2.54:giles@cric.org:111.333.3333
Andy:John:EECS:3.98:john@aj.ece.edu:111.333.4444

I came up with
(grep -n '\<John\>' smallFile)
and get

1:John:Doe:ECE:3.54:doe@jd.home.org:111.222.3333
3:John:Clark:ECE:2.68:clark@xyz.ab.com:111.111.5555
4:John:Lee:EE:2.64:jlee@j.lee.com:111.111.2222
5:Lu:John:CS:3.06:lu.john@xyz.org:111.333.1111
8:Andy:John:EECS:3.98:john@aj.ece.edu:111.333.4444

or
(cat smallFile | grep John)
and get

John:Doe:ECE:3.54:doe@jd.home.org:111.222.3333
John:Clark:ECE:2.68:clark@xyz.ab.com:111.111.5555
John:Lee:EE:2.64:jlee@j.lee.com:111.111.2222
Lu:John:CS:3.06:lu.john@xyz.org:111.333.1111
Andy:John:EECS:3.98:john@aj.ece.edu:111.333.4444

what do I need to change to
(grep -n '\<John\>' smallFile)
to get

1:John:Doe:ECE:3.54:doe@jd.home.org:111.222.3333
3:John:Clark:ECE:2.68:clark@xyz.ab.com:111.111.5555
4:John:Lee:EE:2.64:jlee@j.lee.com:111.111.2222

Last edited by jetoutant; 11-23-2017 at 04:39 PM.. Reason: typos
# 2  
Old 11-23-2017
Moderator's Comments:
Mod Comment Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in the Homework & Coursework forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

Please repost your question in the proper forum.

This thread is closed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Assistance with my one line command to find all inactive kernels

Hello Forum, I'm using the following command to find all inactive kernels installed on my RHEL server: $ rpm -qa | grep '^kernel-' |grep -vE `uname -r` but the result is in two lines: kernel-3.10.0-1062.1.1.el7.x86_64 kernel-3.10.0-1062.el7.x86_64 Is there a one line command I can... (3 Replies)
Discussion started by: greavette
3 Replies

2. Homework & Coursework Questions

Student needs grep command help

I am a Student in college struggling with Linux homework This home work was created by my professor not out of the class text book and is frustrating me and the text book is a little frustrating as well need help with 2 5 6 stuck on 2 currently so I know 5 and 6 will be even more... (9 Replies)
Discussion started by: jetoutant
9 Replies

3. UNIX for Dummies Questions & Answers

Sed/command assistance

Hello, I'm attempting to play with sed commands again... I have a file named test1 with numbers...ex:5551234567 I run this sed on the file... cat test1 | sed 's/^/homeDnModify "/g' | sed 's/$/" "" 3/g' >test2 Im hoping it will look like this... homeDnModify "551235" "4567" ""... (5 Replies)
Discussion started by: jay11789
5 Replies

4. UNIX for Dummies Questions & Answers

Sed/command assistance

Hello all, I need some help and education creating a script. Basically I have a file with a list of numbers.. 2125554444 2124445555 I need to put them into a format that looks like this.... UQ-V8.1,2125554444,hdaudio UQ-V8.1,2124445555,hdaudio Any help would be greatly... (6 Replies)
Discussion started by: jay11789
6 Replies

5. UNIX for Dummies Questions & Answers

[Solved] Assistance with find command please

Trying to locate files less than xx days old, throughout all directories/subdirectories, but excluding certain types of directories and files. The directories I want to search all contain the same characteristic (dbdef, pldef, ghdef, etc), and there are subdirectories within that I need to... (2 Replies)
Discussion started by: Condmach
2 Replies

6. Shell Programming and Scripting

Assistance to use ls and GREP

Hi We have several folders and subfolders in a heirarchy, representing clients and files we send to them. Files that are not processed are placed in reject folder. I am able to run a LS that will scan all these folders, and ones that show entries (rejected files) are seen here. I am looking for... (8 Replies)
Discussion started by: cdc01
8 Replies

7. Homework & Coursework Questions

Grep expressions homework, need assistance

Please dont delete, im listing my assignment and will be editing as i work on it. I am NOT looking for answers but help in understanding how to use grep 1. The problem statement, all variables and given/known data: For each question, list the command lines used in addition to any other details... (3 Replies)
Discussion started by: alindner
3 Replies

8. Shell Programming and Scripting

Grep Alerting - command or script assistance

Hello! I need some help with grep from various logs we use for monitoring transactions. The logs contain the following information (which is consistent in all of the files): 12:28:33.157 EWY D 1 (tcpip.c:282): tcpip.c: Unable to connect to x.x.x.x on port xxxx. (79) Connection refused ... (1 Reply)
Discussion started by: sbchecko
1 Replies

9. UNIX for Dummies Questions & Answers

Command assistance

Hi, We currently use the below basic scripts to output details that the business requires for our AIX and Sun servers. I have been asked to produce the same sort of script to be used for our NCR MP-RAS UNIX and OS/2 UNIX servers but am not formilar with these forms of Unix. Would greatly... (0 Replies)
Discussion started by: kmuir
0 Replies

10. Shell Programming and Scripting

Perl script assistance; paste word into external command

I'm attempting to create a Perl script that will: Take the contents of the usernames.tmp file (usernames.tmp is created from an awk one-liner ran against /etc/passwd) Take one line at a time and pass it to the su command as a users name. This should go on until there is no more name to... (10 Replies)
Discussion started by: bru
10 Replies
Login or Register to Ask a Question