Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

strange file format processing

Shell Programming and Scripting


Tags
awk, formatting, sed, shell

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 11-14-2010   -   Original Discussion by etl_guy
etl_guy etl_guy is offline
Registered User
 
Join Date: Nov 2010
Last Activity: 17 June 2011, 4:22 PM EDT
Posts: 1
Thanks: 3
Thanked 0 Times in 0 Posts
strange file format processing

hi
i have file (a metadata type file ) in this format

Code:
 
record
string("|") isxml ;
string("|") billing_type ;
string("|") billing_type_desc ;
string("|") ods_create_date ;
string("|") ods_update_date ;
string("|") event_key ;
string("|") target_pid ;
string("|") open_date ;
string("|") close_date ;
end

I want the output where the lines with date in it to be changed to
string("|") to date("YYYY-MM-DD")
so output will be

Code:
 
record
string("|") isxml ;
string("|") billing_type ;
string("|") billing_type_desc ;
date("YYYY-MM-DD") ods_create_date ;
date("YYYY-MM-DD") ods_update_date ;
string("|") event_key ;
string("|") target_pid ;
date("YYYY-MM-DD") open_date ;
date("YYYY-MM-DD") close_date ;
end


Last edited by Scott; 11-15-2010 at 02:53 AM.. Reason: Please use code tags
Sponsored Links
    #2  
Old Unix and Linux 11-15-2010   -   Original Discussion by etl_guy
Chubler_XL's Unix or Linux Image
Chubler_XL Chubler_XL is offline Forum Staff  
Moderator
 
Join Date: Oct 2010
Last Activity: 20 November 2017, 7:35 PM EST
Posts: 3,420
Thanks: 147
Thanked 1,212 Times in 1,112 Posts

Code:
awk ' ($2 ~ ".*date.*") { $1="date(\"YYYY-MM-DD\")" } 1' infile

The Following User Says Thank You to Chubler_XL For This Useful Post:
etl_guy (11-15-2010)
Sponsored Links
    #3  
Old Unix and Linux 11-15-2010   -   Original Discussion by etl_guy
pravin27 pravin27 is offline Forum Advisor  
Advisor
 
Join Date: Sep 2009
Last Activity: 21 June 2017, 2:44 PM EDT
Location: ./India/Bangalore
Posts: 1,271
Thanks: 70
Thanked 299 Times in 290 Posts
How about this,

Code:
 sed 's/\(.*\) \+\(.*date.*\)/date("YYYY-MM-DD") \2/g' inputfile

    #4  
Old Unix and Linux 11-15-2010   -   Original Discussion by etl_guy
michaelrozar17's Unix or Linux Image
michaelrozar17 michaelrozar17 is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 22 September 2016, 3:57 AM EDT
Location: IN
Posts: 894
Thanks: 15
Thanked 183 Times in 174 Posts
alternative with sed..

Code:
sed '/date/s/|/YYYY-MM-DD/g' inputfile > outfile


Last edited by michaelrozar17; 11-15-2010 at 03:07 AM..
The Following User Says Thank You to michaelrozar17 For This Useful Post:
etl_guy (11-15-2010)
Sponsored Links
    #5  
Old Unix and Linux 11-15-2010   -   Original Discussion by etl_guy
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 22 November 2017, 8:17 PM EST
Location: Amsterdam
Posts: 11,625
Thanks: 518
Thanked 3,381 Times in 2,980 Posts

Code:
sed '/date/s/.*|/date("YYYY-MM-DD/' file

The Following User Says Thank You to Scrutinizer For This Useful Post:
etl_guy (11-15-2010)
Sponsored Links
    #6  
Old Unix and Linux 11-15-2010   -   Original Discussion by etl_guy
rdcwayx rdcwayx is offline Forum Advisor  
Use nawk in Solaris
 
Join Date: Jun 2006
Last Activity: 13 September 2015, 8:58 PM EDT
Posts: 2,759
Thanks: 44
Thanked 420 Times in 408 Posts

Code:
date=$(date +%Y-%m-%d)

awk ' ($2 ~ /date/) { $1="date(\"" "'$date'" "\")"}1' infile


record
string("|") isxml ;
string("|") billing_type ;
string("|") billing_type_desc ;
date("2010-11-15") ods_create_date ;
date("2010-11-15") ods_update_date ;
string("|") event_key ;
string("|") target_pid ;
date("2010-11-15") open_date ;
date("2010-11-15") close_date ;
end

Sponsored Links
Closed

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
Convert UNIX file format to PC format Samtel Shell Programming and Scripting 2 08-27-2009 06:26 PM
unable to format usb stick ?strange things happening as well!!! wrapster Solaris 3 05-27-2008 09:59 AM
To convert multi format file to a readable ascii format gaur.deepti UNIX for Dummies Questions & Answers 5 03-25-2008 04:03 PM
Convert UTF8 Format file to ANSI format rajreddy UNIX for Dummies Questions & Answers 9 05-25-2007 09:26 AM
Convert UTF8 Format file to ANSI format rajreddy UNIX for Advanced & Expert Users 1 05-24-2007 07:40 AM



All times are GMT -4. The time now is 03:41 AM.