Shell script to copy particular file from directories recursively
I have directory path in which there are several sub directories. In all these sub dir there will be one env.cnf file. I want to copy this env.cnf file from
each sub dir's and place them in destination path by creating same filename as sub dir_env.cnf.
After copying env.cnf files from source to destination dir, I have to run few unix commands(grep) on each files and print the grep command o/p in result files in output dir.
I have seen that we can use the below command to do the recursive file copy part but don't know how to process grep command on each files
Ex:
path : /tmp/config/ has 3 sub dir's
after running the script, it should place the env.cnf file in input dir in /tmp/Config/input as name:
now run the same script again on each files present in the input dir to perform grep command and put the output in output dir in /tmp/Config/output/
ManyThanks,
Thanks Chubler. your solution did work as expected but am trying change the ouput file name as *_result.txt. I tried to update this line like this but didn't work
Could you please tell me what am doing is correct in above stmt and if possible can you tell me how to acrchive this generated file (input/output) to someother path. so that if we run this script again it should genreated the new set of input/output file then it should generate new compare result file by comparing pervious result and new result file.
like :
1. generate input/result file (already done by above script)
2. If we run the above script again, it should check if there is any files present in output folder if yes, then move this genereated files to someother location with datetime stamp in the filename(archive) . if no files found then just generate files.
3. from step 2, if new set of results files generated (if files archived), then should compare archived result file to newly genereated result file.
ie, something like this
please do help me on this.
Hi all,
I'm trying to write a script to recursively cd into my Git projects and pull them, and will later expand it to build my projects as well.
I'm having a bit of trouble with my current script, as I want to supply a command line argument to tell it which branch to check out. I can hard... (2 Replies)
i have directory dgf
in the dgf( some other Sub-dir are there)
00 01 02 03 04
in all the Sub directory there is a SG.csv ..
i want the scripts should run one by one Sub-dir and print the result for that particular Sub-dir ..then go to next Sub-Dir and print the result.......
please... (6 Replies)
Hi,
I am writing a script to copy certain file name in txt file .
It is working fine if I provide a single directory name (for example "/eos/uscms/store/user/pooja04//analysis2012/525/data/doubleele/2012/datav1/" ) where those specific files are present ending with *root .
But I want to modify... (14 Replies)
hi all
I want a script that will use ftp to copy folder and sub folders from source server to current server. if i use -r switch then it just copies folders for 5 level. (1 Reply)
Hi,
Seems like I need help again with a problem:
I want to delete all files from my lets say "Music" Directory inkluding all of the subfolders
except for .mp3 and .MP3 files.
I tried it with globalignoring mp3 files, finding and deleting all other files, which
resulted in all files... (3 Replies)
Hi,
I want a script shell to automate modifying httpd.conf file for
several instances of apache, save httpd.file before changing it, after
modifying it and then restart apache.
- Replace ServerRoot "xxxx" by ServerRoot "yyyy" of all directories :
"... (4 Replies)
Hi guys,
I have just been bothered by a fairly small issue for some time now. I am trying to search (using find -name) for some .jpg files recursively. This is a Redhat environment with bash.
I get this job done though I need to copy ALL of them and put them in a separate folder BUT I also... (1 Reply)
Dear all,
I have a database with thousands of files with the structure of name is:
Filename_hour_year.abc
Filename_hour_year_1.abc
..............
So what I need is how to write a script that all file with contain the character "_1" will copy to "_2"
For example: file name:... (7 Replies)
Hi,
Please help me, how to get all the direcotries, its sub directories and its sub directories recursively, need to exclude all the files in the process.
I wanted to disply using a unix command all the directories recursively excluding files.
I tried 'ls -FR' but that display files as... (3 Replies)
Hello-
I need to copy a file into multiple directories, and each directory's sub-directories (of which there are 5)
Currently, the parent directory is set up like this:
dir1
sub-dir1
sub-dir2
sub-dir3
sub-dir4
sub-dir5
dir2
sub-dir1
sub-dir2
sub-dir3
... (1 Reply)