awk Flat File Conversion Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk Flat File Conversion Script
# 1  
Old 12-20-2013
awk Flat File Conversion Script

In awk how would I flatten input.txt to output.txt?

Input:
Code:
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:
Code:
Darth,Vadar,d.vadar@deathstar.com,dv12345,1234567890
Carlito,Brigante,c.brigante@paradise.com,cb12345,2134567890

# 2  
Old 12-20-2013
What have you tried and what problems are you getting?
What language are you best in?
What OS and version are you on?
What rules for the conversion are there?

... but most importantly, what have you tried and what problems are you getting?



Robin
# 3  
Old 12-20-2013
Modify this according to your need, please use search option before posting

Change the vertical logs to horizontal line by Akshay Hegde - Shell Programming and Scripting - Unix Linux Forums

Not Tested
Code:
$ awk -F":" '{printf NF ? $2 OFS : RS}END{printf RS}' file

OR
Code:
$ awk -F":" '{printf (NR > 1 && /^givenname:/) ? RS $2 OFS : $2 OFS }END{printf RS} ' file


Last edited by Akshay Hegde; 12-20-2013 at 02:03 PM..
This User Gave Thanks to Akshay Hegde For This Post:
# 4  
Old 12-23-2013
Ideal - worked a treat.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to place value at 24 field in a flat file issue

I am trying to add 0393 value at 24th feild using the below command, but its adding at all the lines including header and trailer Input file: ZHV|2657|D0217001|T|TXU|Z|PAN|20131112000552||||OPER| 754|52479| 492|489|SP40|1014570286334|20131111|20131201|14355334|CHAMELON... (1 Reply)
Discussion started by: Aditya_001
1 Replies

2. Shell Programming and Scripting

awk to delete fields from flat file

I would like to know awk command to delete the specific feild from a flat file delimited by '|' if the first feild starts with 354 I tried awk 'BEGIN {FS=OFS="|"} {$16=""; sub(/\|/, "")}'1 Input file: 354|||||GROUND||97||JUDD STREET|||LONDON||WC1H 9JG|ADI001| 354|||||FLAT 1... (10 Replies)
Discussion started by: Aditya_001
10 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

SED | Awk flat file one liner

sed awk one liner (2 Replies)
Discussion started by: jap2614
2 Replies

5. Shell Programming and Scripting

use awk to ssh from variable in flat file

flat file looks like ooss-pfgg-1234,vol_name_1, mail-list decoded = hostname,volum_name,mail_list each line has diff info am trying to ssh into each fist field, check vol usage for second field, and if greater than 90% send mail to mail-list got the second and third part working, ... (1 Reply)
Discussion started by: riegersteve
1 Replies

6. 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

7. Shell Programming and Scripting

File conversion and awk

Hi Everyone, I am confused with the output of the input file and I am using below command in script to get the expected output. Also I want to add another condition using logical AND (&&) in place of $2=="L"{$4=0-$4} as $2=="L" && $3=="L" {$4=0-$4} but I am getting some awk error. Can someone... (6 Replies)
Discussion started by: gehlnar
6 Replies

8. Shell Programming and Scripting

Awk to convert a flat file to CSV file

Hi , I have a file with contents as below: Contract Cancellation Report UARCNCL LOS CODE DATE REAS TYPE AMOUNT AMOUNT LETTER BY ========= ======= ==== ==== ==== ========= ==== ==== 8174739 7641509 1S NONE CRCD 30-JUN-2008 NPAR N .00 .00 CCAN 8678696 8091709 1S NONE DDEB 30-JUN-2008... (14 Replies)
Discussion started by: rkumudha
14 Replies

9. Shell Programming and Scripting

awk script for date conversion

hi awk script for dd/mm/yyyy to yyyymmdd awk script for dd-mon-yyyy to yyyymmdd awk script for dd-mm-yyyy to yyyymmdd formate ..............urgent............. Thanks in advanced (2 Replies)
Discussion started by: charandevu
2 Replies

10. UNIX for Advanced & Expert Users

Flat File Conversion Format

Hi all, I've a flat file in this format: = " Record 1 Field1 -> XXXX Field2 -> 9558 Field3 -> 55AA Record 2 Field1 -> YYYY Field2 -> 12345 Field3 -> aa23 " And i want to convert it to (4 Replies)
Discussion started by: Loobian
4 Replies
Login or Register to Ask a Question