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

use awk to view results of a grep command

Experts,
I forget awk - if something else (perl) works better, then tell me how to do this in perl.  I grep for a certain expression and I would like to use vi to look at each of the results.  I know that "vi +5 afile" will run vi and put you on line 5 of "afile".  Is there some command line that I can tyype to automate looking up files.  Ignoring syntax (which is wrong):

            vi  +`awk line number and filename expression`

I would like this to put me at the proper line on each of the relevant files where the expression I am grepping for is found.
0
dwcronin
Asked:
dwcronin
  • 4
  • 3
1 Solution
 
ozoCommented:
`awk '/expression/{print NR}' file`
0
 
dwcroninAuthor Commented:
I'm back in windows for a little bit but - it doesn't look like that will do it.  "vi" is not mentioned anywhere and where is the " +line number".  The point was to scan all of the files in a directory for an expression and then to have vi open up each file at the proper line.
0
 
ozoCommented:
vi  +`awk '/expression/{print NR}' file`
0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
dwcroninAuthor Commented:
That doesn't seem to do anything.  How about:

grep -nr grid_row_1 *

will print out all of the files along with line numbers that contain the expressionn "grid_row_1".  I would like to use awk to take this information and then use "vi +........" to go to a specific line number in  a specific file.  Any guesses there??

0
 
ozoCommented:
vi  +`grep -nr grid_row_1 * | awk -F: '{print $2,$1;exit}'`
0
 
dwcroninAuthor Commented:
That did it!!!  Thank you very much Ozo.  This will save me a lot of effort at work.

Thanks!
0
 
dwcroninAuthor Commented:
I thought that I should add this comment: this doesn't quite work the way that I was wanting.  Ozo got the awk command to give the output that I wanted, but vi doesn't edit the files the way that I was hoping.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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