I am new to script and I want find one string from multiple files in diff directories and put that out put to new file.
Like I have A,B & C directories and each has multiple files but one file is unic in all the directories like COMM.txt
Now I want write script to find the string "Jack" and what ever get the output lines need to redirect into my home directory
Yes, there is one more req with that. in sub directories, each dir has one file name with Jack.txt and other files are diff names. but i want to go to each sub dir's and search the string in only that file and when it get result it should create same file name in my home dir for each file search and put the result init.
sorry for keep asking....
actually the file name in each dir is jack<yr>.txt and in each sub dir the file has with yr ext.
When it send the result to result.dat, all going into that file, but each file result should go to with same file name in home dir instead into single file
I am still confused.
your files are "jack<year>.txt" or with year extension eg jack.<year> ?
you wrote both the things.
Better give an example with the sample file names.
as per my understanding:
for file in $(find /path/to/parent/dir/of/A,B,C/ -type f -name "*.txt")
do
grep 'Jack' $file > $HOME/$(basename $file).result
done
you can change the result file name whatever you want.
Hope some one can help me for my small req.
I have big log file and it has many error messages.
I want to write script to search for string "Error" and where ever it find it should print full line of it.
exp: cat file.txt
This is test file
Error: user not found
connecting database
Error: Server not found
output should be:
Error: user not found
Error: Server not found
Thanks