issue on reading the file and appending date


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers issue on reading the file and appending date
# 1  
Old 06-04-2009
issue on reading the file and appending date

Hi

Am having issue on appending time stamp

I know the exact file names in the directory like

a.dat
b.dat
c.dat
e.dat
f.dat

I want to read all these file names and append the timestamp to each files like
a.dat.20090604,b.dat.20090604 and move to the different directory.

FILE_NAMES="a.dat b.dat c.dat d.dat e.dat"
echo $FILE_NAMES >file1
while read line
do
mv $line /ac/de/$line.`date +%Y%m%d%H%M`
done<file1

This not working ,since we are decalring the filenames in a single line.

Please help/suggest me the method to do this.
# 2  
Old 06-04-2009
How about that:

Code:
for NAME in $FILE_NAMES
do
   mv $NAME /ac/de/$NAME.`date +%Y%m%d%H%M`
done

# 3  
Old 06-04-2009
Prabhu,

you can do it in two ways:

1> If you have to write the file name in single line then you need to cut each file name before you add the time stamp.

you can try some thing like this

Code:
`cut -d" " -f1 $line`.`date +%Y%m%d%H%M`

you need to have a counter for cutting the feilds ( -f$i )

2> Second way is to write 1 file name per line.

in this case your logic should work.

Let us know if you need further help!

Smilie

Last edited by shubhendu; 06-04-2009 at 05:36 AM..
# 4  
Old 06-04-2009
Thanks Alot For the prompt reply GUYS!!
appriciated!!
It worked!!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk issue while reading from file in while do

Hi Friends, I am trying to scan line by line using awk and pull the values and pass it in variables and then will use the variables but doesn't work. Please see below for details. #more dbtest.sh ---------------------------------- #!/bin/bash . $HOME/.bash_profile while read line do... (6 Replies)
Discussion started by: narunice
6 Replies

2. UNIX for Dummies Questions & Answers

Appending Date at the end ONLY in first line of file

Hi, My requirement is to append a date in format DDMMYYYYHHMISS at the end of first line of file which is HEADER. I am trying command sed -i '1s/.*/&<date_format>/' <file_name> Where <date_format>=`date +%m%d%Y%H%M%S` I am somehow misisng the right quotes ti get this added in above... (2 Replies)
Discussion started by: sanjaydubey2006
2 Replies

3. Shell Programming and Scripting

Reading a date from a file

Seems like this should be an easy thing to do (in bash shell), but can't get it figured out. We don't have an kind of scheduling functionality on our test system, so I'm trying to emulate having a process run every 8 hours, by using a control file with a date, and checking it every few minutes.... (5 Replies)
Discussion started by: billrow
5 Replies

4. UNIX for Dummies Questions & Answers

Appending date value mmdd to first column in file

Hi , I have a file with a running sequence number. I need to append a date value mmdd format on to the first column. for e.g.: The file contains records as 001 abc 002 cde 003 edf 004 fgh 005 hik The output should be 1111001 abc 1111002 cde 1111003 edf 1111004 ... (1 Reply)
Discussion started by: kalyansid
1 Replies

5. UNIX for Dummies Questions & Answers

Appending the current date on Copying the file.

Hi I have the data file in the one directory and i have to copy the file in the another directory with the timestamp. EX: /ab/cd/a.dat i need to copy this file to the another directory /ef/gh/. while am copying i need to append the current timestamp in the file like... (3 Replies)
Discussion started by: bobprabhu
3 Replies

6. Shell Programming and Scripting

appending date at the end of the file

I have file called xx Now i want to rename this file as xxYYYYMMDD_HHMIAM.xls Here is my code.. export DATE1=`date +%Y%m%d` mv xx xx$DATE1 This code renames as xxYYYYMMDD Now how can i append HHMIAM at the end of the file? Any help is appreciated... (3 Replies)
Discussion started by: govindts
3 Replies

7. Shell Programming and Scripting

Reading specific contents from 1 input files and appending it to another input file

Hi guys, I am new to AWK and unix scripting. Please see below my problem and let me know if anyone you can help. I have 2 input files (example given below) Input file 2 is a standard file (it will not change) and we have to get the name (second column after comma) from it and append it... (5 Replies)
Discussion started by: sksahu
5 Replies

8. UNIX for Dummies Questions & Answers

reading ,writing,appending ,manipulating a file.

Hi my prob statement is to create a new file or to append to the 1tst file the followign chages. File 1: txt file. portfolio No a b c d abc 1 Any Any Any charString cds 2 values values values charString efd 3 can can can charString fdg 4 come come come charString... (4 Replies)
Discussion started by: szchmaltz
4 Replies

9. Shell Programming and Scripting

Date Not appending in log file

Hi experts . . . Sunsolaris 9 version I have the script as below: Am getting log file as : archive_today_.log Please suggest. ################################################## set 'date' dd=$3 mon=$2 export mon yyyy=$6 export yyyy cd /oracle/P47/saparch (4 Replies)
Discussion started by: vrjalli
4 Replies

10. Shell Programming and Scripting

Reading specific contents from a file and appending it to another file

Hi, I need to write a shell script (ksh) to read contents starting at a specific location from one file and append the contents at specific location in another file. Please find below the contents of the source file that I need to read the contents from, File 1 -----# more... (5 Replies)
Discussion started by: dnicky
5 Replies
Login or Register to Ask a Question