Register
It is currently Thu Apr 24, 2014 10:27 pm

Help with piping the output of grep


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Sun Jan 31, 2010 8:35 am   

Joined: Sun Jan 31, 2010 8:28 am
Posts: 2
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


Top
 Profile  
 PostPosted: Sun Jan 31, 2010 9:31 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 512
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


Last edited by Watael on Sun Jan 31, 2010 1:50 pm, edited 4 times in total.

Top
 Profile  
 PostPosted: Sun Jan 31, 2010 12:17 pm   

Joined: Sun Jan 31, 2010 8:28 am
Posts: 2
Works
Thanks!


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Majestic-12 [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP