![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to find a file named vijay in a directory using find command | amirthraj_12 | UNIX for Dummies Questions & Answers | 6 | 10-25-2008 09:37 AM |
| Can I know find syntax to find given date files | bache_gowda | Shell Programming and Scripting | 3 | 03-26-2008 03:37 AM |
| Little bit weired : Find files in UNIX w/o using find or where command | jatin.jain | Shell Programming and Scripting | 10 | 09-19-2007 03:47 AM |
| Find files older than 20 days & not use find | halo98 | Shell Programming and Scripting | 2 | 05-18-2006 11:19 AM |
| command find returned bash: /usr/bin/find: Argument list too long | yacsil | Shell Programming and Scripting | 1 | 12-15-2003 03:38 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
find and mv files in single line
I have a.txt and b.txt (and so on ) in a directory.
I need to move these files to a.xml , b.xml and so on, basically I just need to rename all the XXX.txt files to XXX.xml using find and mv , how can we do it? something like below, but it is not right find . -name '*.txt' -exec mv {}\.xml \; Any ideas? Thanks Muru Last edited by muru; 06-29-2006 at 03:05 PM. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
If you have the mmv command, you can just do
Code:
mmv '[ab].txt' '#1.xml' |
|
#3
|
|||
|
|||
|
Thanks for your reply, unfortunately SunOs 5.7 doesn't seem to have mmv.
is there any way we could achieve this by following pseudo find mv [the file given by find to] ["work on the result of find to cut just the file name without extension" and add our extension (ie .xml)] instead using cut and appening the .xml, could we use sed to replace extension to .xml and move the original file to this name? I am sorry if this is not achievable. Thanks Muru |
|
#4
|
|||
|
|||
|
Code:
#!/bin/ksh
find /path -name '*.txt' | \
while read file
do
newfile=${file%.txt}".xml"
mv $file $newfile
done
|
|
#5
|
||||
|
||||
|
You can use something like this:
#!/bin/sh for vo in *.txt do ao=`echo $vo | sed "s/\..*$//"` mv "$vo" "$ao".xml done |
|
#6
|
|||
|
|||
|
Thanks for the reply, both the above suggestions works.
Can we do it in a single line using something like this for file in `ls *.txt` ;do mv $file `sed 's/\..*$/.txt/'`;done this doesn;t work, but I feel that this may work with minor tweaks. Thanks again for the reply! |
|
#7
|
|||
|
|||
|
Code:
find /path -name '*.txt' | while read file ;do ; newfile=${file%.txt}".xml" ; mv $file $newfile ; done
|
|||
| Google The UNIX and Linux Forums |