![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| file command | rprajendran | UNIX for Advanced & Expert Users | 3 | 05-13-2008 10:45 AM |
| rm command not able to remove file | jambesh | Shell Programming and Scripting | 7 | 12-21-2007 04:37 AM |
| What is the command to add heading to a file? | whatisthis | UNIX for Dummies Questions & Answers | 3 | 12-02-2005 12:17 AM |
| VI command for File Please | $Circle$ | UNIX for Dummies Questions & Answers | 12 | 09-05-2005 01:23 AM |
| End of file using more command | Enda Martin | UNIX for Dummies Questions & Answers | 3 | 06-18-2001 07:49 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
using <B>Bourne shell</B> how can I list all files in such a directory that file name don't match a pattern.
e.g: a dir. /mydir contains these files [tamer001]-/mydir$ ls 2001-01-23.log 2001-01-23_08-30.log 2001-01-23_15-59.log 2001-01-24_00-00.log 2001-01-24_11-52.log 2001-01-24_18-34.log 2001-01-25.log 2001-01-25_13-30.log I want to move all files except the files of 25th of the month (which is today files) and rename the files by adding a string to the begining of the file name. so here what I did: Code:
#!/usr/bin/sh
dir=/var/dist
cd /mydir
for file in *.log
do
if [ -f $file ]
then
if /usr/bin/mv $file $dir/access_log_$file
then
echo "$file : moved to $dir successfuly "
else
echo "can not move or rename access_log_$file"
fi
fi
done
please help. [Edited by tamer on 01-28-2001 at 05:42 PM] added code tags for readability --oombera Last edited by oombera; 02-19-2004 at 02:38 PM. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
DATE=`/bin/date "+%Y-%m-%d"`
for file in !(${DATE}*.log); do do ... done |
|
#3
|
|||
|
|||
|
Quote:
but is this in Bourne Shell !! because this error occured after running the script test.sh: syntax error at line 7: `!' unexpected Code:
#!/usr/bin/sh
dir=/var/dist
cd /mydir
DATE=`/usr/bin/date "+%Y-%m-%d"`
for file in !(${DATE}*.log);
do
if [ -f $file ]
then
if /usr/bin/mv $file $dir/access_log_$file
then
echo "$file : moved to $dir successfuly "
else
echo "can not move or rename access_log_$file"
fi
fi
done
Last edited by oombera; 02-19-2004 at 02:38 PM. |
|
#4
|
||||
|
||||
|
Sorry, I dont know enough about the Bourne shell to help you. My answer will work in bash or ksh.
|
|
#5
|
|||
|
|||
|
OK thanks PxT.
any one can help me. |
|
#6
|
||||
|
||||
|
Tamer: Seems like a good exercise to take PxT's script and convert it to the shell script you want. I thought PxT did a great job answering this for you. After all, if you have the script in one shell, it should be minimal work to figure out how to convert it to another. It is good practice for you to do a little 'shell conversion' don't you think? Please post your version when you are finished so others can learn from your work too!
|
|
#7
|
|||
|
|||
|
Quote:
Thanks; but I was spent 2 days to write 200 line of code to logroll my mail server log files, zip them and transfer them to another server for anther purposes; and this was the only problem I faced, anyway I will do it and post it again. |
|||
| Google The UNIX and Linux Forums |