Unix/Linux Go Back    


UNIX for Dummies Questions & Answers This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in this forum UNIX for Beginners Questions & Answers

awk : dynamic output flatfile filename

UNIX for Dummies Questions & Answers


Tags
awk filename, solved

 
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 06-02-2016
Tipiak Tipiak is offline
Registered User
 
Join Date: Jun 2016
Last Activity: 6 June 2016, 4:34 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
awk : dynamic output flatfile filename

Hello,

I'm using the awk command to insert empty columns on a tab delimited flatfile - which works fine -
=> But I'm not able to manage dynamicaly the filename of the awk output based on the source flatfile filename

I have 3 source flatfile:

Code:
flatfile_Jan-2016.csv
flatfile_Feb-2016.csv
flatfile_Mar-2016.csv

And I would like to output the result of the awk command to

Code:
newflatfile_Jan-2016.csv
newflatfile_Feb-2016.csv
newflatfile_Mar-2016.csv

Below the awk command which is working for inserting empty columns but I'm not able to manage dynamically the target flatfile filename


Code:
awk -F"\t" '$6="\t" $6' OFS="\t" *flatfile* > flatfile_Jan-2016.dat


Thanks!



Moderator's Comments:
awk : dynamic output flatfile filename Please use code tags as required by forum rules!

Last edited by RudiC; 06-02-2016 at 12:04 PM.. Reason: Added code tags.
Sponsored Links
    #2  
Old Unix and Linux 06-02-2016
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 20 October 2017, 2:22 PM EDT
Location: Aachen, Germany
Posts: 11,479
Thanks: 310
Thanked 3,561 Times in 3,276 Posts
Try (untested):
Code:
awk -F"\t" '{$6="\t" $6; print > ("new" FILENAME)' OFS="\t" *flatfile*

Sponsored Links
    #3  
Old Unix and Linux 06-02-2016
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 20 October 2017, 4:55 PM EDT
Location: San Jose, CA, USA
Posts: 10,550
Thanks: 554
Thanked 3,694 Times in 3,151 Posts
Quote:
Originally Posted by RudiC View Post
Try (untested):
Code:
awk -F"\t" '{$6="\t" $6; print > ("new" FILENAME)' OFS="\t" *flatfile*

Note that to avoid processing newflatfile_Mon-YEAR.csv files if you run this script multiple times, you probably want to just use flatfile* instead of *flatfile* as the filename matching pattern in your script.
    #4  
Old Unix and Linux 06-06-2016
Tipiak Tipiak is offline
Registered User
 
Join Date: Jun 2016
Last Activity: 6 June 2016, 4:34 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
thank you all, it is working like a charm!
Sponsored Links
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
AWK specific output filename LMSteed Shell Programming and Scripting 10 08-10-2012 09:00 PM
sending output to flatfile spmsarada Shell Programming and Scripting 4 02-16-2012 01:55 PM
How to use a dynamic filename with sed? ericonanson Shell Programming and Scripting 4 12-10-2009 12:13 PM
how to include field in the output filename of awk yahyaaa Shell Programming and Scripting 4 08-15-2008 12:10 PM
Dynamic filename in awk Indalecio Shell Programming and Scripting 2 01-23-2007 06:34 AM



All times are GMT -4. The time now is 05:33 PM.