Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I print the file name and a match given a list?

Status
Not open for further replies.

acoble

Programmer
Nov 30, 2000
6
US
I am using the following command:
find . -name *.queryInputs -ls | sort -k 8,10

This gives me a list of files that are sorted by date. It is basically ls -la returning only files ending in queryInputs. I would like to take the list of files and print the file name followed by a matching string found in each file. I don't want to use grep because it prints the entire line that the match occurred in. I am trying to find the string:

queryName: '<name>'

Where <name> varies from file to file. I want to print the value of <name> after the file name.

Is this possible?

Thank you for your help,
Al
 
Something like this ?
awk -F: '/queryName/{printf "%s:%s\n",FILENAME,$2}' *.queryInputs

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
That worked with some modification. I had to change : to , and change *.queryInputs. It seems the filenames are too long. I needed to change it to output_Q9*.queryInputs. It seems there is a limit on the number of characters * can represent. I still have to work on "9" being included in * because it is not a constant.

Is there a way to extract a string from a particular column (i.e., in $2 /quernName: \'(.*)\'/ where the string in () is what I want to print)?

Thank you for your help,
Al
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top