|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Renaming file and check for the renamed file existence
Hi Am trying to move a file from one name to another When I do "ls" to check for the moved filename I can see the file but when I try the same with a script am unable.. I think am doing some pretty silly error.. please help.. Code:
toMove=`ls | grep -E "partition.[0-9]+"`
mv $toMove partition.[0-9]_org
if [ $? -eq 0 ]; then
echo "Success.. The value of $toMove"
else
echo "FAIL"
fi
#Checking for file has transferred..
toFind=`ls | grep -E "partition.[0-9]_org"`
if [ $? -eq 0 ]; then
echo "Success.. The value of $toFind "
else
echo "FAIL"
fiHere the value toFind returns a FAIL state..
Last edited by Priya Amaresh; 02-28-2013 at 07:42 AM.. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Use it without Grep Code:
toFind=`ls "partition.[0-9]_org"` Last edited by Vikram_Tanwar12; 02-28-2013 at 07:53 AM.. |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
I'm sorry but did not understand what you are trying to achieve here. Why are you creating a file with a odd name ??? Code:
mv $toMove partition.[0-9]_org |
|
#4
|
||||
|
||||
|
You should specify path for the
ls command
toMove=`ls /etc | grep -E "partition.[0-9]+"` Do not use back ticks `` if its possible toMove=$(ls /etc | grep -E "partition.[0-9]+") and as paynam write: you try to move all file matching pattern partition.[0-9]+ to one singe file with this name partition.[0-9]_org I think you try to move files like this partition.12 to partition.12_org or this partition.45465 to partition.45465_org Last edited by Jotne; 02-28-2013 at 07:57 AM.. |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Hi
Its a file generated during installation thats why the odd filename exists |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
I think here you are renaming the file to
partition.[0-9]_org .So when you try using the RE,it won't find any file. Better use Code:
mv $toMove "$toMove"_org instead of Code:
mv $toMove partition.[0-9]_org And in the part were you check if the operation was successfull, I think you missed out the "+".It should have been Code:
toFind=`ls | grep -E "partition.[0-9]+_org"` And better escape the "." Last edited by Franklin52; 03-01-2013 at 02:11 AM.. Reason: fixed code tags |
| The Following User Says Thank You to chacko193 For This Useful Post: | ||
Priya Amaresh (03-01-2013) | ||
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
So you search one singe file with this exact name
partition.[0-9]+ to name
partition.[0-9]_org
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Script to check for the file existence, if file exists it should echo the no of modified days | karthikeyan_mac | Shell Programming and Scripting | 2 | 08-03-2011 07:08 AM |
| To check for existence of a file | manutd | UNIX for Dummies Questions & Answers | 1 | 07-20-2011 02:04 AM |
| How to check for file existence? | mingming88 | Shell Programming and Scripting | 1 | 04-28-2009 10:20 AM |
| Check for File Existence | dsdev_123 | AIX | 4 | 08-08-2008 07:30 PM |
| check for file existence | dsdev_123 | AIX | 2 | 06-26-2008 01:08 PM |
|
|