BashScripts.org
http://bashscripts.org/forum/

Help with piping the output of grep
http://bashscripts.org/forum/viewtopic.php?f=15&t=978
Page 1 of 1

Author:  Musturd [ Sun Jan 31, 2010 8:35 am ]
Post subject:  Help with piping the output of grep

Here is what I want to accomplish:
move all files matching a certain phrase in their name to a new directory and unzip them all.
There are thousands of files so I'd rather not do this manually.

After trying a few things I ended up with:
Code:
mv $(ls | grep '<phrase>') /usr/local/etc/destination
cd /usr/local/etc/destination
unzip $(ls)


Which would work I think if all the filenames did not include spaces. But they do.
How can I either
1) remove all spaces in the file names (but I would rather keep them)
or (preferably)
2) get this script to work without removing the spaces in the filenames

Thanks

Author:  Watael [ Sun Jan 31, 2010 9:31 am ]
Post subject:  Re: Help with piping the output of grep

Hello Musturd,

Code:
Src="."
Dst=/usr/local/etc/destination
for file in $Src/*phrase*
do [[ -f $file ]] && {
      dest="$Dst/${file##*/}"
      mv "$file" "$dest"
      unzip "$dest"
   }
done

Author:  Musturd [ Sun Jan 31, 2010 12:17 pm ]
Post subject:  Re: Help with piping the output of grep

Works
Thanks!

Page 1 of 1 All times are UTC - 6 hours
© 2000, 2002, 2005, 2007 phpBB Group • http://www.phpbb.com