Flat File Conversion Format


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Flat File Conversion Format
# 1  
Old 05-01-2006
Flat File Conversion Format

Hi all,

I've a flat file in this format:
[] = [2 empty lines]
"
Record 1
[]
Field1 -> XXXX
Field2 -> 9558
Field3 -> 55AA
[]
Record 2
[]
Field1 -> YYYY
Field2 -> 12345
Field3 -> aa23
[]
"

And i want to convert it to

XXXX|9558|55AA
YYYY|12345|aa23

so it can be loaded into an oracle table;

Any sugestions; (awk)?

Thnks in advance
# 2  
Old 05-02-2006
a complex way

awk 'BEGIN{OFS="|"} /Field/ {f1=$3;getline;f2=$3;getline;f3=$3; print f1,f2,f3;}' filname

Last edited by ranj@chn; 05-02-2006 at 03:58 AM.. Reason: typo
# 3  
Old 05-02-2006
awk is my AK-46

awk 'BEGIN { FS ~ /->/ ; count=0 }
{ if (NF != 3 ) next ;
outstr="" ;
do { outstr = outstr $3 "\|" ; count++ ; }
while ( count%3 != 0 && getline );
printf "%s\n", substr(outstr, 0, length(outstr)-1) }' /u01/old_record_file

In case above not work perfectly for you then please put your valuable time as well Smilie
# 4  
Old 05-02-2006
Hi,
I don't understand the meanig of "/u01/old_record_file";
I've got 57 fields, so i replace 3 for 57 everywhere and i'm executing this like:
in=$1
out=$2
cat $in | "your co0de" > $out [i removed the above path from the code"

I didn't work... (the format is as follow).

[empty line]
[empty line]
Record -> 1
[empty line]
[empty line]
Field1 ->12345
Field2 ->AAAA
Field3 ->5245A
[empty line]
[empty line]
Record -> 2
[empty line]
[empty line]
{another record}
# 5  
Old 05-02-2006
Hi sumit,

I´ve altered the code to:

cat $in | awk 'BEGIN { FS ~ /->/ ; count=0 }
{ if (NF != 3 || substr($1,1,6)=="Record") next ;
outstr="" ;
do { outstr = outstr $3 "|" ; count++ ; }
while ( count%57 != 0 && getline );
printf "%s\n", substr(outstr, 0, length(outstr)-1) }'

And it work's just fine. Thnks.
Much regards.
L
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk Flat File Conversion Script

In awk how would I flatten input.txt to output.txt? Input: givenname: Darth sn: Vadar mail: d.vadar@deathstar.com uid: dv12345 orclguid: 1234567890 givenname: Carlito sn: Brigante mail: c.brigante@paradise.com uid: cb12345 orclguid: 2134567890 Output: ... (3 Replies)
Discussion started by: u20sr
3 Replies

2. Shell Programming and Scripting

How to change the format of the date column in a flat file?

Hi, i have a flat file namely temp.txt with this data below ID|name|contact_date 101|Kay|2013-12-26 102|let|2013-12-26 I need to modify the date data in the flat file into MM/DD/YYYY HH24:MI:SS format let me know the code for this. Thank you! (5 Replies)
Discussion started by: srikanth_sagi
5 Replies

3. UNIX for Dummies Questions & Answers

Conversion of flat file to Mainframe file

Hi guys, I have a flat file created by ETL tool. Now the flat file has 4 columns. 1st column is a Character(17), 2nd Column Character(4), 3rd column is a decimal column and 4th column is also a decimal column. I have to convert this file into a Mainframe file in the following format. ... (4 Replies)
Discussion started by: mac4rfree
4 Replies

4. Shell Programming and Scripting

conversion of spaces into CSV format file

INput file attached in thread : Column widths at 24,73,82,87,121 characters (sed 's/./,/24;s/./,/73;s/./,/81;s/./,/87;s/./,/121;s/ *, */,/g' fixedinputfile >output.csv ). The client wants instead of hard coding the column widths as they are not fixed .he has given the hint stating that ( ... (3 Replies)
Discussion started by: sreenath1037
3 Replies

5. UNIX for Advanced & Expert Users

Converting the date format in a flat file

Hi All, I am new to this forum, could any one help me out in resolving the below issue. Input of the flat file contains several lines of text for example find below: 5022090,2,4,7154,88,,,,,4/1/2011 0:00,Z,L,2 5022090,3,1,6648,88,,,,,4/1/2011 0:00,Z,,1... (0 Replies)
Discussion started by: av_sagar
0 Replies

6. Shell Programming and Scripting

Conversion of below Tabs Tex file into CSV format file : shell script needed

Request if some one could provide me shell script that converts the below "input file" to "CSV format file" given Name Domain Contact Phone Email Location ----------------------- ------------------------------------------------ ------- ----- ---------------------------------... (7 Replies)
Discussion started by: sreenath1037
7 Replies

7. Ubuntu

Conversion of the format of a file in linux

How to convert a rtf file to a ttf file in ubuntu terminal? (2 Replies)
Discussion started by: poonam.gaigole
2 Replies

8. Shell Programming and Scripting

Flat file to csv conversion

Hi Guy's can someone help me in converting the following I have a flat text file which has several thousand lines which I need to convert to a csv it's got a consistent format but basically want every time it hit's txt to create a new line with the subsequent lines comma delimited for example ... (6 Replies)
Discussion started by: p1_ben
6 Replies

9. Shell Programming and Scripting

format a flat file

i have a flat file with around 700 columns . i want to break it into a flat file with say five columns like col1,col2,col3,col4 col5,col6,col7,col8 col9...... ,col700 how can i do this (5 Replies)
Discussion started by: r_t_1601
5 Replies

10. Shell Programming and Scripting

DateTime Format Conversion in a File

Hi Pals. I have a file which is in the below format. 2007/10/15-12:04:24,'CRLift','TH-42PX75U','BestBuy','W01P0207',22,15,'User1' 2007/10/15-12:04:26,'CRLift','TH-42PX75U','BestBuy','W01P0207',22,15,'User2' 2007/10/15-12:04:29,'CRLift','TH-42PX75U','BestBuy','W01P0207',22,15,'User3'... (4 Replies)
Discussion started by: srikanthgr1
4 Replies
Login or Register to Ask a Question