We help IT Professionals succeed at work.

Display word Pattern as well as display line number

leftridge1
leftridge1 asked
on
Medium Priority
299 Views
Last Modified: 2010-04-21
I having problems trying to display a word and display the number line as well.  for example:

1234       Pete             Jack      57     m   67000
3456       Jackson         Bill       24     f     56000
9999       Jacksnyder    Mort     37     F    4550
7777       Gundeson      Pam     50    f      3500
Comment
Watch Question

Top Expert 2005

Commented:
Is that the input or the desired output?
If it is the input, what is the desired output?
If it is the desired output, what is the input?

It sounds like you want to familiarize yourself with awk.

Author

Commented:
for example I would like to display the word jack as the word or in a pattern search and display the number line as well.  I hope this helps
akw '($0 ~/jack/ {print})' employee

Author

Commented:
My out put should display the word jack or a pattern of jack along with the number displayed.  
CERTIFIED EXPERT
Top Expert 2007

Commented:
grep -n jack employee

Author

Commented:
I want the out put of this command to show on the screen.  
grep -n jack employee - what about printing the lines that have jack as part of the word or word.
CERTIFIED EXPERT
Top Expert 2007

Commented:
I'm having trouble following you.

Using your sample input, this is what you should get:

$ cat employee
1234       Pete             Jack      57     m   67000
3456       Jackson         Bill       24     f     56000
9999       Jacksnyder    Mort     37     F    4550
7777       Gundeson      Pam     50    f      3500
$ grep -n Jack employee
1:1234       Pete             Jack      57     m   67000
2:3456       Jackson         Bill       24     f     56000
3:9999       Jacksnyder    Mort     37     F    4550


Note that I did a search on 'Jack' rather than 'jack'.  If you want it to be case insensitive, then do

grep -ni jack employee

How is the output not meeting your requirements?

Author

Commented:
the out is fine accept it doesn't number the lines 1,2,3.  how do I number the lines 1,2,3 instead of 1,6,8,10
CERTIFIED EXPERT
Top Expert 2007
Commented:
Ahh, when you said line number, I thought you wanted the line number of the match.  If you just want a sequential number then do

grep -i jack employee | nl

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.