Recursively search the string from a column in no. of files


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Recursively search the string from a column in no. of files
# 1  
Old 05-22-2013
Recursively search the string from a column in no. of files

i have a file named keyword.csv(contains around 8k records) which contains a no. of columns.
The 5th column contains all the keywords.
I want to recursively search these keywords in all .pl files(around 1k) and display the filename....Afterthat i will use the filename and some of the column from the keyword.csv to update the database.

I am using below code...but it is not working as keyword.csv contains a no of columns...

find . -type f -name "*.pl" | xargs fgrep -f keyword.csv

Could you please let me know how to handle it.
Thank you in advance.

Last edited by millan; 05-22-2013 at 08:23 AM..
# 2  
Old 05-22-2013
Please use code tags as required by forum rules!

How about (untested!)
Code:
awk 'FNR == NR {X[$5]; next}
     FNR == 1  {found = 0}
     !found    {for (i in X) if (match ($0, i) {print FILENAME; found = 1; break }
    ' FS="," keyword.csv FS=" " *.pl

If your awk has sth like nextfile, use that instead of break ...
# 3  
Old 05-22-2013
Thank you Rudic..
I tried your code but it is giving error as below.
Code:
$ awk 'FNR == NR {X[$5]; next}
     FNR == 1  {found = 0}
     !found    {for (i in X) if (match ($0, i) {print FILENAME; found = 1; break }
    ' FS="," keyword.csv FS=" " *.pl
> > > awk: syntax error near line 3

awk: bailing out near line 3


I am using SunOS.
And also just now i modified the question..that i want the filename as well as 10th and 5th coloumn in the output..

Please let know how to do it.

Last edited by jim mcnamara; 05-22-2013 at 09:30 AM..
# 4  
Old 05-22-2013
Citing Don Cragun:
Quote:
on Solaris, use /usr/xpg4/bin/awk , /usr/xpg6/bin/awk , or nawk instead of awk .
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search strings from a file in files in a directory recursively; then print the string with a status

Hi All, I hope somebody would be able to help me. I would need to search a string coming from a file, example file.txt: dog cat goat horse fish For every string, I would need to know if there are any files inside a directory(recursively) that contains the string regardless of case.... (9 Replies)
Discussion started by: kokoro
9 Replies

2. Shell Programming and Scripting

Search for string in column using variable: awk

I'm interested to match column pattern through awk using an external variable for data: -9 1:751343:T:A -9 0 T A 0.726 -5.408837e-03 9.576603e-03 7.967536e-01 5.722312e-01 -9 1:751756:T:C -9 0 T C 0.727 -5.360458e-03 9.579447e-03 7.966977e-01 5.757858e-01... (7 Replies)
Discussion started by: genome
7 Replies

3. Shell Programming and Scripting

Search string in multiple files and display column wise

I have 3 files. Each of those files have the same number of records, however certain records have different values. I would like to grep the field in ALL 3 files and display the output with only the differences in column wise and if possible line number File1 Name = Joe Age = 33... (3 Replies)
Discussion started by: sidnow
3 Replies

4. Shell Programming and Scripting

How can I use find command to search string/pattern in a file recursively?

Hi, How can I use find command to search string/pattern in a file recursively? What I tried: find . -type f -exec cat {} | grep "make" \; Output: grep: find: ;: No such file or directory missing argument to `-exec' And this: find . -type f -exec cat {} \; -exec grep "make" {} \;... (12 Replies)
Discussion started by: cola
12 Replies

5. Shell Programming and Scripting

Search/Replace in multiple files recursively

Hi there, I am using AIX and trying to search and replace a string with another string in multiple files in different directories. I wanted to search replace in steps so I don't change all of the instance anywhere in the server at once, minimizing impact. STEP 1: -------- I first searched... (5 Replies)
Discussion started by: zaino22
5 Replies

6. Linux

Search files recursively

grep pattern filename To search for the pattern in all files in the current directory and the sub-directories recursively, what needs to be substituted in filename? (1 Reply)
Discussion started by: ravisingh
1 Replies

7. Shell Programming and Scripting

Search in a column by a string

Hi All, My file looks like : hsdhj dsajhf jshdfajkh jksdhfj jkdhsfj shfjhd shdf hdsfjkh jsdfhj hdshf sdjh dhs foot dsjhfj jdshf dasfh jdsh dsjfh jdfshj david Now, I want to search entire column by a string... (10 Replies)
Discussion started by: naw_deepak
10 Replies

8. Shell Programming and Scripting

find and replace a search string recursively in files

Hi , I have a directory structure as dir and subdirectories and files under it and so on.now I need to find the files which contain the search string under every dir and subdir and replace . my search string is like searchstring=/a/b string to be replaced=/a/c/b please help. ... (7 Replies)
Discussion started by: mohanpadamata
7 Replies

9. Shell Programming and Scripting

Search for string dublicates in column

Hi I have a file with one column. There are a few replicas in this column, that is some lines look exactly the same. I want to know the ones that occur twice. Inputfile.xml "AAH.dbEUR" "ECT.dbEUR" "AEGN.dbEUR" "AAH.dbEUR" "AKZO.dbEUR" ... Here I would like to be informed that... (7 Replies)
Discussion started by: lulle
7 Replies

10. Shell Programming and Scripting

String search and return value from column

Dear All I had below mention file as my input file. 87980457 Jan 12 2008 2:00AM 1 60 BSC1 81164713 Jan 12 2008 3:00AM 1 60 BSC2 78084521 Jan 12 2008 4:00AM 1 60 BSC3 68385193... (3 Replies)
Discussion started by: jaydeep_sadaria
3 Replies
Login or Register to Ask a Question