Hello, I am new in shell scripting. I need help regarding following.
I have 4 files generated by backups daily. I have stored the names of these 4 files into one file. i.e I have 4 files names as a, b, c & d and these names have been put into one file abcd.txt.
Now I want to cat each file in abcd.txt and grep for a string and put the output in another file.
I am not able to sort it out for myself and would appreciate if anyone can help me in this.
Welcome to forums, enjoy learning/knowledge sharing here. For your query could you please try following and let me know if this helps you.
while read line
do
find -type f -name $line -exec grep "Your_String" >> Output_file
done < "abcd.txt"
Also above code is NOT tested as your requirement was not that clear, so if above doesn't help you please come with more details and all conditions which you have in your requirement too, hope this helps you.
Thank you Ravinder for your help. Following is the detailed info for which I seek help. I have 4 log files auto generated by some binary with the names as given below.
-rw------- 1 nz nz 7.9K May 8 14:07 backupsvr.16897.2016-05-08.log
-rw------- 1 nz nz 4.1K May 8 14:23 backupsvr.7474.2016-05-08.log
-rw------- 1 nz nz 162K May 8 14:38 backupsvr.25848.2016-05-08.log
-rw------- 1 nz nz 47K May 8 18:40 backupsvr.29230.2016-05-08.log
What I did is that I listed the files of my choice of date and put the names into another file by using the following command.
ls *`date +%Y-%m-08`* > output.txt
Not the new file "output.txt" contains all 4 file names from 08th May 2016.
Now I want to fetch 2nd last line from each file and put them into one new file. i.e 2nd last line of 1st file is as "a completed successfully". 2nd file's 2nd last line is "b completed successfully".
I want these 2nd last line into one final file which output would be as below.
#cat finalfile.txt
a completed successfully
b completed successfully
c completed successfully
d completed successfully
I hope my requirement is clear now. If not please let me know and I will try to explain it more.