strange file format processing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting strange file format processing
# 1  
Old 11-14-2010
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
# 2  
Old 11-15-2010
Code:
awk ' ($2 ~ ".*date.*") { $1="date(\"YYYY-MM-DD\")" } 1' infile

This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 11-15-2010
How about this,
Code:
 sed 's/\(.*\) \+\(.*date.*\)/date("YYYY-MM-DD") \2/g' inputfile

# 4  
Old 11-15-2010
alternative with sed..
Code:
sed '/date/s/|/YYYY-MM-DD/g' inputfile > outfile


Last edited by michaelrozar17; 11-15-2010 at 03:07 AM..
This User Gave Thanks to michaelrozar17 For This Post:
# 5  
Old 11-15-2010
Code:
sed '/date/s/.*|/date("YYYY-MM-DD/' file

This User Gave Thanks to Scrutinizer For This Post:
# 6  
Old 11-15-2010
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

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 to format one txt file to required format

Hello Everyone, I have one source file which is genarated by SAP in different format(Which I've never seen). I need to convert that file to required format and I need to read this target file from Datastage to use this in my Jobs. So I do not have any other options except to use Unix script to... (4 Replies)
Discussion started by: Prathyu
4 Replies

2. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies

3. Shell Programming and Scripting

Converting windows format file to unix format using script

Hi, I am having couple of files which i used to copy from windows to Linux, so now in case of text files (CTRL^M) appears at end of line. I know i can convert this windows format file to unix format file by running dos2unix. My requirement here is that i want to do it automatically using a... (5 Replies)
Discussion started by: sarbjit
5 Replies

4. Shell Programming and Scripting

Convert UNIX file format to PC format

Hi All, Is there any way to convert a file which is in UNIX format to a PC format.... Flip command can be used , apart form this command can we have any other way.... like usinf "awk" etc ..... main purpose of not using flip is that my Kshell doesnot support this comamnd.... (2 Replies)
Discussion started by: Samtel
2 Replies

5. UNIX for Dummies Questions & Answers

Convert UNIX file format to PC format

Hi All, Is there any way to convert a file which is in UNIX format to a PC format.... Flip command can be used , apart form this command can we have any other way.... like usinf "awk" etc ..... main purpose of not using flip is that my Kshell doesnot support this comamnd.... (1 Reply)
Discussion started by: Samtel
1 Replies

6. Solaris

unable to format usb stick ?strange things happening as well!!!

Hi all, I have a pendrive that is fat formatted... It was being detected so far on solairs...but now during the re-installation of solaris ,i did not remove the drive and guess i screwed it up... since then , i am unable to use it...guess its now not formatted or is corrupt... but the irony... (3 Replies)
Discussion started by: wrapster
3 Replies

7. UNIX for Dummies Questions & Answers

To convert multi format file to a readable ascii format

Hi I have a file which has ascii , binary, binary decimal coded,decimal & hexadecimal data with lot of special characters (like öƒ.ƒ.„İİ¡Š·œƒ.„İİ¡Š· ) in it. I want to standardize the file into ASCII format & later use that as source . Can any one suggest a way a logic to convert such... (5 Replies)
Discussion started by: gaur.deepti
5 Replies

8. UNIX for Dummies Questions & Answers

Convert UTF8 Format file to ANSI format

:confused: Hi i am trying to convert a file which is in UTF8 format to ANSI format i tried to use the function ICONV but it is throwing error Function i used it as $ iconv -f UTF8 -t ANSI filename Error iam getting is NOT Supported UTF8 to ANSI please some help me out on... (9 Replies)
Discussion started by: rajreddy
9 Replies

9. UNIX for Advanced & Expert Users

Convert UTF8 Format file to ANSI format

:) Hi i am trying to convert a file which is in UTF8 format to ANSI format i tried to use the function ICONV but it is throwing error Function i used it as $ iconv -f UTF8 -t ANSI filename Error iam getting is NOT Supported UTF8 to ANSI please some help me out on this.........Let me... (1 Reply)
Discussion started by: rajreddy
1 Replies

10. Filesystems, Disks and Memory

Strange difference in file size when copying LARGE file..

Hi, Im trying to take a database backup. one of the files is 26 GB. I am using cp -pr to create a backup copy of the database. after the copying is complete, if i do du -hrs on the folders i saw a difference of 2GB. The weird fact is that the BACKUP folder was 2 GB more than the original one! ... (1 Reply)
Discussion started by: 0ktalmagik
1 Replies
Login or Register to Ask a Question