![]() |
|
|
|
|
|||||||
| 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 03:37 AM |
| What is the command to add heading to a file? | whatisthis | UNIX for Dummies Questions & Answers | 3 | 12-01-2005 11:17 PM |
| 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 | Display Modes |
|
|||
|
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 01:38 PM. |
| Forum Sponsor | ||
|
|
|
|||
|
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 01:38 PM. |
|
|||
|
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 |