Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Check for files with different ext

Original Message
Name: hismail
Date: March 14, 2006 at 07:32:48 Pacific
Subject: Check for files with different ext
OS: Sco Openserver
CPU/Ram: 2gig/4gig
Model/Manufacturer: Sco
Comment:
Hi
i want to know is there a way to create a variable where I have a multile list of files called :
audit.12
audit.13
audit.14
I need to copy these files to another directory but keeping them with a date extension
I tried this ,but no luck:
#!/bin/ksh
DATE=`date +%d%m%y`
CONO=`grep [0-1][0-9]`
cp audit.$CONO /home/singgm/bckaudit
cd bckaudit
cp audit.$CONO audit.$CONO.$DATE


Thanks in advance
Hamim


Report Offensive Message For Removal


Response Number 1
Name: nails
Date: March 14, 2006 at 09:06:34 Pacific
Subject: Check for files with different ext
Reply: (edit)
A way. No error checking:


#!/bin/ksh

adir="/home/singgm/bckaudit"

DATE=$(date +%d%m%y)

ls -1 audit.*|while read file
do
cp $file $adir
cp $file $adir/$file.$DATE
done


Report Offensive Follow Up For Removal

Response Number 2
Name: hismail
Date: March 14, 2006 at 23:01:39 Pacific
Subject: Check for files with different ext
Reply: (edit)
Hi Nails
I tried your option ,but it gives me erors
:UX:cp: ERROR: Incorrect usage
UX:cp: TO FIX: Usage: cp [-i] [-p] f1 f2
cp [-i] [-p] f1 ... fn d1
cp [-i] [-p] [-r] d1 d2


Report Offensive Follow Up For Removal

Response Number 3
Name: nails
Date: March 15, 2006 at 09:35:45 Pacific
Subject: Check for files with different ext
Reply: (edit)
That's a very straight forward script. It works on my Solaris 8 box. I'm not an HP-UX guy

The only problem I could see is if you spaces in your files or directories. Try places quotes around your variables:

cp "$file" "$dir"


Report Offensive Follow Up For Removal

Response Number 4
Name: hismail
Date: March 16, 2006 at 02:21:09 Pacific
Subject: Check for files with different ext
Reply: (edit)
Hi nails
ok Thanks
I did however come up with this solution as well:

dir="/home/singgm/bckaudit"
DATE=`date +%d%m%y`
for FILE in $1 `ls audit.*`
do
chmod 444 $FILE
cp $FILE $dir/$FILE.$DATE
done



Report Offensive Follow Up For Removal

Response Number 5
Name: nails
Date: March 16, 2006 at 11:02:01 Pacific
Subject: Check for files with different ext
Reply: (edit)
If it works for you fine, but let me point out a potential problem the way you use the for loop:

Your script works because you have only 1 server name per line with no white space. Let's change the algorithm. Suppose you had to read a text file a line at a time which might contain whitespace:

for line in `cat myfile`
do
echo "$line"
done

suppose myfile contains this for data:

col11 col22
col14 col24

If you wanted to echo just two lines, the script fails.

Here's what you want to do

while read line
do
echo "$line"
done < myfile

In conclusion, you are using what's commonly called a Useless Use of Cat, UUOC. For more info, take a look at this link:

http://laku19.adsl.netsonic.fi/%7Eera/unix/award.html

I'm not being mean - just sharing information.


Report Offensive Follow Up For Removal


Response Number 6
Name: arun.s
Date: March 25, 2006 at 02:35:11 Pacific
Subject: Check for files with different ext
Reply: (edit)
guys,

how about this.just see the below solution. let me know if it goes fine.

#!/bin/ksh
dir="/home/signgm/bckaudit"
datestamp=`date +%d%m%y`
ls -l audit.*|while read file
do
file=`echo $file|tr -s " " ";"|cut -d ";" -f9`
cp $file $dir
cp $file $dir/$file.$datestamp
done

thanks
Arun S


this unix location and u have placed windows request. please specify on which platform u want solution.


Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Check for files with different ext

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




acer 312T BIOS problem

K7 Turbo possible max fsb?

Pc anywher problem

WinFLP & OE/Outlook2003

Computer resets after a few minutes


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC