Help in code logic for merging 3 files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help in code logic for merging 3 files
# 1  
Old 01-04-2012
Help in code logic for merging 3 files

Hi all,
I have a requirement to merge 3 files which has different record count.
Ex:
File1-SOUTHLANG
Code:
01;HINDI
02;TELUGU
03;ITALIAN
04;KOREAN
05;ENGLISH

File2-LANGDET
Code:
INDIA;80 
SOUTHINDIA;60
ITALY;100

File3-LANGYEAR
Code:
400;VERYOLD
1200;OLD
200;VERYOLD

I have merged these files using paste command as
Code:
paste -d ";\0" SOUTHLANG LANGDET LANGYEAR > LANG.txt

and got output as
Code:
01;HINDI;INDIA;80;400;VERYOLD
02;TELUGU;SOUTHINDIA;60;1200;OLD
03;ITALIAN;ITALY;100;200;VERYOLD
04;KOREAN;
05;ENGLISH;

But I require output like
Code:
01;HINDI;INDIA;80;400;VERYOLD
02;TELUGU;SOUTHINDIA;60;1200;OLD
03;ITALIAN;ITALY;100;200;VERYOLD
04;KOREAN;;;;
05;ENGLISH;;;;

I mean blank value with delimiter shall print when there are no values in the specific file.
Please help me in coding this.

Thanks,
SRK.

Last edited by Franklin52; 01-04-2012 at 08:37 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 01-04-2012
Try this,

Code:
paste -d ";\0" SOUTHLANG LANGDET LANGYEAR | awk -F';' '{ if (NF<5) { print $0";;;" } else { print $0 } }'

# 3  
Old 01-04-2012
Sorry...Its not working.

It just adding ';;;' at the end of each record.

The logic here is to merge 3 files and during concatenation when there is no data in a file for a record it should be filled with blank value '' and demilted.
Such that output file will be having some data in all fields.
# 4  
Old 01-04-2012
Code:
paste -d ';' SOUTHLANG LANGDET LANGYEAR | nawk -F';' '{NF=6;$1=$1;print}' OFS=';'

Login or Register to Ask a Question

Previous Thread | Next Thread

2 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell program code logic

Hi, I have a file (log data) with the sample code as follows /apps/opt | go_gen.ksh | #START | jan 28 06:15 |/home/dump /apps/opt | go_gen.ksh | #END | jan 28 06:30 |/home/dump /apps/opt | pend_instl.ksh | #START | jan 28 09:50 |/home/dump /apps/opt | pend_instl.ksh | #END | jan... (3 Replies)
Discussion started by: karthikd214
3 Replies

2. Shell Programming and Scripting

Apply transformation logic in 2 different files

:)Transformation logic on column values in two different files, File A 12345,000,4444, HKD3.5 12346,000,5555, HKD3.5 File B 12345,4444,54321,6666 12346,5555, 64321,7777 12347,5555, 65321,8888 Requirement as below 1.read file A 2. match with File B ie if (fileA.column1... (1 Reply)
Discussion started by: HAA
1 Replies
Login or Register to Ask a Question