- Community Home
- >
- Servers and Operating Systems
- >
- Legacy
- >
- Operating System - Tru64 Unix
- >
- renaming files containing a pattern
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-04-2004 01:30 AM
тАО03-04-2004 01:30 AM
i'm trying to find a way to list all the files in a given directory that contacin a certain pattern and then move all the matching files into another directory.
i've tried every combination of grep and find i can think of but i'm getting nowhere fast
most recently i tried the snippet below but no joy. any advice would be much appreciated
for file in 'grep -l "pattern" *'
do
mv $file /dir
done
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-04-2004 01:34 AM
тАО03-04-2004 01:34 AM
Re: renaming files containing a pattern
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-04-2004 01:54 AM
тАО03-04-2004 01:54 AM
Re: renaming files containing a pattern
how do i list the files containing a pattern with find,
i've only used find when i know the filenames before.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-04-2004 02:45 AM
тАО03-04-2004 02:45 AM
SolutionEilish, You are on the right track. Just need a back-tick instead of a single quotes!
This works for me:
$ for file in `grep -l aap x*`
> do
> echo "File " $file " should be moved"
> done
File x should be moved
File x1 should be moved
File x3 should be moved
I might be tempted to use xargs though!
grep -l aap x* | xargs -i echo "move file {} please!"
move file x please!
move file x1 please!
move file x3 please!
Or awk:
grep -l aap x* | awk '{system("echo move " $1 " now.")}'
Or a perl script to glob to the directory, open, read, on patternmatch close and move.
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-04-2004 02:46 AM
тАО03-04-2004 02:46 AM
Re: renaming files containing a pattern
for i in `ls -l | tr -s " " " " | cut -f 9 -d " "`
do
if test `grep -c pattern $i` != "0"
then
mv $i /dir
fi
done
Regards
Ninad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-04-2004 02:47 AM
тАО03-04-2004 02:47 AM
Re: renaming files containing a pattern
what is grep for? Example move all files with ending text:
for FILE in *.txt
do
mv ${FILE} /dir/
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-04-2004 02:53 AM
тАО03-04-2004 02:53 AM
Re: renaming files containing a pattern
thanks for your help I've been pulling my hair out trying to get it right.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-04-2004 02:54 AM
тАО03-04-2004 02:54 AM
Re: renaming files containing a pattern
try this:
grep -l "pattern" searchfiles|xargs -n1 -I{} mv "{}" /dir/
greetings,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-04-2004 07:08 PM
тАО03-04-2004 07:08 PM
Re: renaming files containing a pattern
What works fine now ?
There are scripts that will move the file when the content of the file contains a pattern.
And there is a script that will move the file when the filename contains a certain pattern.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-04-2004 10:22 PM
тАО03-04-2004 10:22 PM
Re: renaming files containing a pattern
ls -Tl | awk '($9==1999){print $10}' | xargs mv /home/darryl/test
will move all files with date 1999 to /home/darryl/test....