Results 1 to 3 of 3
Hi,
The below script takes a date and table name from the user. It unzips and untar a file from archive folder based on date. Then select the required file ...
- 08-06-2010 #1Just Joined!
- Join Date
- Jul 2010
- Posts
- 16
find and cp not working
Hi,
The below script takes a date and table name from the user. It unzips and untar a file from archive folder based on date. Then select the required file based on the tablename provided and copy it to ../posextract folder.The folder posextract contains already extracted files for the user.
1) The find command throws error with *. However when I try without *, it is not finding the required files.Code:echo "Enter date \n" read lookdate echo "Enter Table Name\n" read tablename cd $POS_ARC find . -name *$lookdate* -exec cp {} ../postempextract \; cd ../postempextract gunzip * | tar -xvf - find . -name *$tablename* -exec cp {} ../posextract \; rm *
2)Can we modify the above script to avoid the use of ../postempextract here?
Thanks
Maya
- 08-06-2010 #2
When you use wildcards in an argument to a program, you must prevent those wildcards from being expanded by the shell. To do so, enclose them in either single quotes or double quotes. In your case, you need double quotes, to allow interpolation of the enclosed variable.
--- rod.Code:find . -name "*$lookdate*" -exec cp {} ../postempextract \;Last edited by theNbomr; 08-06-2010 at 01:44 PM.
Stuff happens. Then stays happened.
- 08-06-2010 #3
I just saw the second part of your question...
To solve the problem of temporary files, instead use variables that contain filenames, and use grep to filter those...
--- rod.Code:for file in $(echo $(find . -name "*$lookdate*" ) | grep $tablename); do cp $file ../posextract done
Stuff happens. Then stays happened.


Reply With Quote