move files using regular expressions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting move files using regular expressions
# 1  
Old 03-29-2012
move files using regular expressions

Hi,
I have bunch of files in my home directory which starts with "s" and I need to move them into a directory. How can I use regex to do that?
some of file names are:
sample-script
say-now
script1
# 2  
Old 03-30-2012
try this
Code:
flist=`find ~ -name s\* -type f | tr "\n" " "`; 
mv $flist $destination

This User Gave Thanks to 47shailesh For This Post:
# 3  
Old 03-30-2012
is there any easier way to do that from command line?
eg. mv [^s]* ./mydir

I am not sure how to use regex though...
# 4  
Old 03-30-2012
yeah for moving everything starting from s directly use mv

Code:
mv s* destination_dir

if not running from home dir use this
Code:
mv ~/s* destination_dir

# 5  
Old 03-30-2012
now how can i say move everything start with s and end with one digit number?

is it ok: mv s*$[1-9] ./mydirectory
# 6  
Old 03-30-2012
You don't need the dollar sign.

Code:
s*[0-9]

To test what might work, use the ls command:

Code:
ls s*[0-9]

It will list the files that match, and thus the files that would be put on the move command line. So you can see what you will move before attempting it.
This User Gave Thanks to agama For This Post:
# 7  
Old 03-30-2012
Dear agama, You helped me a lot before... Would you please kindly take a look at this question that I posted here:
https://www.unix.com/shell-programmin...data-file.html
Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regular Expressions

Hi Ilove unix and alwyas trying to to learn unix,but i am weak in using regular expressions.can you please give me a littel brief discription that how can i understand them and how to use .your response could lead a great hand in my unix love. (1 Reply)
Discussion started by: manoj attri
1 Replies

2. UNIX for Dummies Questions & Answers

files and Regular expressions

Legends, Please help me out. I have the following two files. And i want to list all of them using a regular expression. How do i do that? abc000 abc000.gz Now if i use ls -ltr abc000 it doesn't work. Please help. (9 Replies)
Discussion started by: sdosanjh
9 Replies

3. Shell Programming and Scripting

Help with regular expressions

I have a file that I'm trying to find all the cases of phone number extensions and deleting them. So input file looks like: abc x93825 def 13234 x52673 hello output looks like: abc def 13234 hello Basically delete lines that have 5 numbers following "x". I tried: x\(4) but it... (7 Replies)
Discussion started by: pxalpine
7 Replies

4. Shell Programming and Scripting

Regular expressions help

need a regex that matches when a number has a zero (0) at the end of it so like 10 20 120 30 330 1000 and so on (6 Replies)
Discussion started by: linuxkid
6 Replies

5. Shell Programming and Scripting

Need help with Regular Expressions

Hi, In ksh, I am trying to compare folder names having -141- in it's name. e.g.: 4567-141-8098 should match this expression '*-141-*' but, -141-2354 should fail when compared with '*-141-*' simlarly, abc should fail when compared with '*-141-*' I tried multiple things but nevertheless,... (5 Replies)
Discussion started by: jidsh
5 Replies

6. UNIX for Advanced & Expert Users

Regular Expressions

Hi, below is a piece of code written by my predecessor at work. I'm kind of a newbie and am trying to figure out all the regular expressions in this piece of code. It is really a tough time for me to figure out all the regular expressions. Please shed some light on the regular expressions... (3 Replies)
Discussion started by: ramky79
3 Replies

7. UNIX for Dummies Questions & Answers

regular expressions

how to find for a file whose name has all characters in uppercase after 'project'? I tried this: find . -name 'project**.pdf' ./projectABC.pdf ./projectABC123.pdf I want only ./projectABC.pdf What is the regular expression that correponds to "all characters are capital"? thanks (8 Replies)
Discussion started by: melanie_pfefer
8 Replies

8. Shell Programming and Scripting

regular expressions

Hello, Let say I have a string with content "Free 100%". How can extract only "100" using ksh? I would this machanism to work if instead of "100" there is any kind of combination of numbers(ex. "32", "1238", "1"). I want to get only the digits. I have written something like this: ... (4 Replies)
Discussion started by: whatever
4 Replies

9. Shell Programming and Scripting

regular expressions

Hi, can anyone advise me how to shorten this: if || ; then I tried but it dosent seem to work, whats the correct way. Cheers (4 Replies)
Discussion started by: jack1981
4 Replies

10. Programming

regular expressions in c++

How do I use the regular expressions in c++? (2 Replies)
Discussion started by: szzz
2 Replies
Login or Register to Ask a Question