• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 285
  • Last Modified:

Display word Pattern as well as display line number

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
0
leftridge1
Asked:
leftridge1
  • 4
  • 3
1 Solution
 
brettmjohnsonCommented:
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.
0
 
leftridge1Author 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
0
 
leftridge1Author Commented:
My out put should display the word jack or a pattern of jack along with the number displayed.  
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
TintinCommented:
grep -n jack employee
0
 
leftridge1Author 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.
0
 
TintinCommented:
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?
0
 
leftridge1Author 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
0
 
TintinCommented:
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
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now