Append string to filename


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Append string to filename
# 1  
Old 05-24-2012
Append string to filename

Hi,
i wrote the script like...

Code:
v_date=`date "+%Y%m%d"`;
v_date1="rejects_"$v_date'.txt';
echo $v_date1;
awk -F\| 'NF==4{ print $0>$v_date1;next} NF!=4 {print $0 >"murali.txt";next}' test1.txt

while append data into file as coming like file is $v_date1,but i want data into file rejects_20120524.txt.

Please help me.
# 2  
Old 05-24-2012
You need to send the value of the variable using -v option to awk

Code:
awk -F\| -v date=$v_date1 'NF==4{ print $0>date;next} NF!=4 {print $0 >"murali.txt";next}' test1.txt

# 3  
Old 05-24-2012
Thanks lot...
one more small change ,instead of "murali.txt" how to pass the file name..as like same
# 4  
Old 05-24-2012
yes, it can be done in similar way, use -v for every variables passed.
Code:
awk -F\| -v date=$v_date1 -v file=$filename 'NF==4{ print $0>date;next} NF!=4 {print $0 >file;next}' test1.txt

# 5  
Old 05-24-2012
ROCK...AWESOME...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help on how to append on the filename when condition met.

Hi All, Seeking for your assistance on how to append the specific string when $3 condion met. ex. file1.txt ar0050046b16,5,888,0,0,0,0.00,0.00,0.00,0.00,25689.55 ar0050046b16,5,0,0,0,0,0.00,0.00,0.00,0.00,25689.55 ar0050046b16,5,0,0,0,0,0.00,0.00,0.00,0.00,25689.55 expected output:... (5 Replies)
Discussion started by: znesotomayor
5 Replies

2. Shell Programming and Scripting

Help Needed! - Cut characters after a text string and append to end of filename

Hi all.. I have several unique files that contain one thing in common, and that is acct#. For all files in the directory, I want to append the 10 characters following the word "ACCOUNT:" to the end of the filename. for example: I have file 111_123 that contains ACCOUNT:ABC1234567 The file... (5 Replies)
Discussion started by: cinderella1
5 Replies

3. Shell Programming and Scripting

How to append filename to rows in gzip stdout

Assume I have 2 gz files with 2 lines each as below a.gz a1,a a2,a b.gz b1,b b2,b If I issue gzip -d -c *.gz I will get below in the stdout a1,a a2,a b1,b b2,b What I need it the filename appended to each row either at the front or back. a.gz,a1,a a.gz,a2,a (2 Replies)
Discussion started by: ericlim
2 Replies

4. Shell Programming and Scripting

append a filename with system date and time

Hi, There are similar kind of posts, but none seems like working for me. Please correct me if I'm wrong. I need append/rename file abc.txt with file processed date and time like abc_systemdatetimestamp.txt and move it to different folder. for example I have /source/data/abc.txt ... (1 Reply)
Discussion started by: amsn08
1 Replies

5. Shell Programming and Scripting

how to append current date to filename.tgz in perl

i would like to know how to append current date in a filename with .tgz extension. #!/usr/bin/perl my $date = `date + %Y%m%d`; system("sudo mv /tmp/nyucs01_config_backup.tgz /misc/nyucs01_config_backup_$date.tgz"); im getting this error message: sh: line 1: .tgz: command not found (7 Replies)
Discussion started by: linuxgeek
7 Replies

6. UNIX for Dummies Questions & Answers

Shell Scripts - Append a filename with date and time....

Hello, I need to create a shell script that appends a filename to create a name with the date and time appended that is guaranteed to not exist. That is, the script insures you will not overwrite a file with the same name. I am lost with this one. I know I need to use date but after that I am... (3 Replies)
Discussion started by: citizencro
3 Replies

7. UNIX for Dummies Questions & Answers

Append Previous Days date to filename

I need to append previous days date to my file which is generated using a script. I am working on Solaris 10. Thanks! (2 Replies)
Discussion started by: Twisha
2 Replies

8. UNIX for Dummies Questions & Answers

Append filename to datafile

I am working on an shell script which checks for all the file starting with abc*.* and if file found then the filelines need to append the file name in begining can some one help with the filename appending... for i in `ls $filename*.csv` do echo $i --- NEED to append file name befor... (3 Replies)
Discussion started by: Satyagiri
3 Replies

9. UNIX for Dummies Questions & Answers

Append current date to filename

In C Shell programming I haven't successfully been able to append the date in the format mmddyyyy to a filename. I've tried the following: I can print out the date in the correct format: date +%x | sed ‘s/\///g I can create a variable with the filename: set newfile=changedfiles I can... (3 Replies)
Discussion started by: gigigi
3 Replies

10. UNIX for Dummies Questions & Answers

Append date to filename

What is the easiest way to append the date (year, month, day) to a filename? (5 Replies)
Discussion started by: hshapiro
5 Replies
Login or Register to Ask a Question