KSH - Find paths of multiple files in CC (dir and sub-dir))

Dear Members,

I have a list of xml files like

abc.xml.table
prq.xml.table
...
..
.

in a txt file.

Now I have to search the file(s) in all directories and sub-directories and print the full path of file in a output txt file.

Please help me with the script or command to do so.

Thank you very much!

 
find . -type f -name "*.xml" | xargs grep -l "pattern"

A few questions itkamaraj

  1. The "patterns" in above command line will replace the input file in which I have the list of xml files whose path is to be found. Is that right?

  2. The output will be displayed on screen and will not be stored in a file, am I correct?

i misunderstood your problem.

so, you have a text file which has lot of xml files. you need to find out the absolute path of those xml files ?

 
while read filename
do
         find . -type f -name "$filename" 
done < input.txt

okay, sorry to bother you again, but I am a novice and have a little trouble in getting this script functional.

I created a text file filenames.txt which consists

connection_words.xml.table
da_sections.xml.table
directory_issue.xml.table
directory_section.xml.table
doc_type.xml.table

And, then I created a script search_full_path.sh like this

 #!/bin/ksh
 while read filename
do
         find . -type f -name "$filename" 
done < filenames.txt

But when I run this script I get nothing. What am I doing wrong?

replace the . (dot) with the path of the direcotry

 
find .

. means current directory. it will search the file from the current directory.

so replace . with the directory name which you want to search from.

1 Like

Thank you so much.
This works just fine!

I appreciate your patience and prompt response!

---------- Post updated at 03:08 PM ---------- Previous update was at 02:47 PM ----------

If I may, can I ask you one more question?

In all the files that I have searched along with their absolute path, there are multiple occurrences of a tag like <DmidRef RefName="GXPRODKEY"/>.

Now my question is how will I enlist all the words within double quotes (like GXPRODKEY) from among all the files that I have just searched.

 
#!/bin/ksh
while read filename
do
 find . -type f -name "$filename" | xargs nawk -F"[\"=]" ' /DmidRef RefName/ {print $3}'
done < filenames.txt
1 Like

Awesome!
Thank man!

Can you please explain this to me
-F"[\"=]" ' /DmidRef RefName/ {print $3}'

I can understand that print $3 will return the third string/variable.

What does -F"[\"=]" do?

This gives clear picture for your question.

 
$ echo "A:B:C:D:E" | nawk -F: '{print $3}'     # uses :(colon) as delimeter
C

$ echo "A:B|C:D:E" | nawk -F: '{print $3}'    # uses :(colon) as delimeter
D

$ echo "A:B|C:D:E" | nawk -F"[:\|]" '{print $3}' # uses :(colon) & pipe as delimeter

C

so, in your case, i used " (double quotes) and = (equal symbol) as delimeter

1 Like

Great!

Thank you so much!
You made my day!

And this is to check whether the line has the pattern and if yes, then only print the 3rd field.

 
/DmidRef RefName/