![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | 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. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Detecting incoming files without busy polling | baldyeti | Shell Programming and Scripting | 9 | 08-15-2008 11:06 AM |
| script to find the average number or files? | bbbngowc | Shell Programming and Scripting | 2 | 03-27-2008 12:57 PM |
| run a script from incoming email | jojo77 | UNIX for Dummies Questions & Answers | 7 | 02-22-2008 01:48 PM |
| find number of incoming requests to a server | laddu | UNIX for Dummies Questions & Answers | 1 | 03-10-2007 01:48 AM |
| awk script to find the number of files | uni_ajay_r | Shell Programming and Scripting | 4 | 10-31-2006 06:58 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Script to number incoming files
Hey guys,
I am working on a Cshell script and I am stuck on this one part. I need to be able to copy in files to my directory but give them different names so they don't overwrite each other. For example, my folder already contains FILE.1 I want my script to name the next file copied over FILE.2 and the next one FILE.3 and so on. It should be able to tell what files are there and named the new one the next highest value. So I have FILE.1, FILE.2, and FILE.3 in my directory now, If I copy in another file, my script should rename it FILE.4 This script has been driving me nuts all day I can't figure it out. Here is what I have so far. Thanks in advance. New code would be appreciated because I obviously have no clue what I'm doing in this piece. Code:
while (-d FILE.0)
cp -r FILE FILE.1
set ctr = 1
foreach f(*)
set var1 = 'file $f | awk '{printf "%s\n",$3}''
if ($var1 == 1) then
FILE = 'ls $f | cut -f1 -d "."'
1 = 'ls $f | awk -F "." '{printf "%s\n",$2}''
mv $f $FILE$ctr.$1
ctr = 'expr $ctr + 1'
endif
end
end
|
|
||||
|
Code:
#!/bin/sh
i=1
while(a=1)
do
if test -e "FILE."$i
then
let i+=1
else
break
fi
done
cp -f FILE FILE.$i
Last edited by wabard; 03-19-2009 at 08:53 PM.. Reason: FIXED The cp command line argument to -f from -r (I typed the wrong option, r and f are close on the keyboard .. lol ) |
|
||||
|
Dummy variable to force the while to loop forever... you exit out of the infinite loop with the "break" statement. Note: I made a mistake in the "cp" command line option in the example above (corrected and noted). |
|
||||
|
below may help you some
Code:
name=`for i in dir1/*
do
echo $i | sed 's/^\(.*\/\)\([^0-9]*\)\(.*\)/\2 \3/'
done | sort -n +1 | tail -1 | awk '{print $1""($2+1)}'`
cp file_to_be_copied dir1/$name
|
| Sponsored Links | ||
|
|