Sponsored Content
Top Forums Shell Programming and Scripting Shell scripting - need to arrange the columns from multiple file into a single file Post 302780273 by devtakh on Thursday 14th of March 2013 09:45:50 AM
Old 03-14-2013
I will let you figure out how to put a 0 when there is no data.

Code:
$ awk 'BEGIN{while (getline < "file1"){ map[$1]=$2 }}{x=map[$1];if ($1 in map){map[$1]=x" "$2}}END{for (i in map){print i,map[i]}}'  file2 file3 file4

Code:
x 10 100 100
y 20 78 900
z 15 245 23 300


cheers,
Devaraj Takhellambam

---------- Post updated at 09:45 AM ---------- Previous update was at 08:34 AM ----------

Try this....Hope this works.

Code:
awk 'BEGIN{while (getline < "file1"){ map[$1]=$2 }}{if (FNR == 1 && NR > 1){for (i in map){y=map[i];mn=split(y,m," ");if (mn < ln){map[i]=y " " 0;}}};x=map[$1];if ($1 in map){map[$1]=x " " $2;ln=split(map[$1],n," ");}}END{for (i in map){print i,map[i]}}' file2 file3 file4

O/P
Code:
x 10 100 0 100
y 20 0 78 900
z 15 245 23 300


cheers,
Devaraj Takhellambam
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Executing Multiple .SQL Files from Single Shell Script file

Hi, Please help me out. I have around 700 sql files to execute in a defined order, how can i do it from shell script (3 Replies)
Discussion started by: anushilrai
3 Replies

2. Shell Programming and Scripting

how to arrange all lines in a file to a single line

Hi Gurus, I am a starter with shell script. Help me to achieve this. I have a file with lines given below. line1 line2 line3 . . etc How can I arrange the file which should look like line1,line2,line3,..,..,etc Any help on this is appreciated. (9 Replies)
Discussion started by: smv
9 Replies

3. Shell Programming and Scripting

Filtering issues with multiple columns in a single file

Hi, I am new to unix and would greatly appreciate some help. I have a file containing multiple colums containing different sets of data e.g. File 1: John Ireland 27_December_69 Mary England 13_March_55 Mike France 02_June_80 I am currently using the awk... (10 Replies)
Discussion started by: crunchie
10 Replies

4. Shell Programming and Scripting

How to arrange xml tags in single row using shell script?

I want to put one xml record in one row and so on... sample two records are here. <?xml version="1.0"?> <Object> <Header> <XCOMVers>V1.0</XCOMVers> <REPORT>XXXXX</REPORT> <CODE>002</CODE> </Header> <IssueCard> <Record> <L>CAR SYSTEM -SSSSS -</L> ... (1 Reply)
Discussion started by: sene_geet
1 Replies

5. Shell Programming and Scripting

How to arrange xml tags in single row using shell script?

I want to put one xml record in one row and so on... sample two records are here. <?xml version="1.0"?> <Object> <Header> <XCOMVers>V1.0</XCOMVers> <REPORT>XXXXX</REPORT> <CODE>002</CODE> </Header> <IssueCard> <Record> <L>CAR SYSTEM -SSSSS -</L> ... (3 Replies)
Discussion started by: sene_geet
3 Replies

6. Shell Programming and Scripting

Awk match multiple columns in multiple lines in single file

Hi, Input 7488 7389 chr1.fa chr1.fa 3546 9887 chr5.fa chr9.fa 7387 7898 chrX.fa chr3.fa 7488 7389 chr21.fa chr3.fa 7488 7389 chr1.fa chr1.fa 3546 9887 chr9.fa chr5.fa 7898 7387 chrX.fa chr3.fa Desired Output 7488 7389 chr1.fa chr1.fa 2 3546 9887 chr5.fa chr9.fa 2... (2 Replies)
Discussion started by: jacobs.smith
2 Replies

7. Shell Programming and Scripting

how to arrange datas in columns in shell script.

Hello All, I have datas in the below format. Mark 45 Steve 60 Johnson 79 Elizabeth 90 My requirement is to arrange the data in the order as shown in the attachment. My OS is Solaris. ... (6 Replies)
Discussion started by: vashece
6 Replies

8. Shell Programming and Scripting

Combining columns from multiple files into one single output file

Hi, I have 3 files with one column value as shown File: a.txt ------------ Data_a1 Data_a2 File2: b.txt ------------ Data_b1 Data_b2 Data_b3 Data_b4 File3: c.txt ------------ Data_c1 Data_c2 Data_c3 Data_c4 Data_c5 (6 Replies)
Discussion started by: vfrg
6 Replies

9. Shell Programming and Scripting

Tabbed multiple csv files into one single excel file with using shell script not perl

Hi Experts, I am querying backup status results for multiple databases and getting each and every database result in one csv file. so i need to combine all csv files in one excel file with separate tabs. I am not familiar with perl script so i am using shell script. Could anyone please... (4 Replies)
Discussion started by: ramakrk2
4 Replies

10. UNIX for Beginners Questions & Answers

Output file name and file contents of multiple files to a single file

I am trying to consolidate multiple information files (<hostname>.Linux.nfslist) into one file so that I can import it into Excel. I can get the file contents with cat *Linux.nfslist >> nfslist.txt. I need each line prefaced with the hostname. I am unsure how to do this. --- Post updated at... (5 Replies)
Discussion started by: Kentlee65
5 Replies
ypmatch(1)						      General Commands Manual							ypmatch(1)

NAME
ypmatch - print values of selected keys in Network Information Service map SYNOPSIS
domain] Remarks The Network Information Service (NIS) was formerly known as Yellow Pages (YP). Although the name has changed, the functionality of the service remains the same. DESCRIPTION
prints the values associated with one or more keys in a Network Information Service (NIS) map specified by mname. The mname can be either a mapname or a map nickname. A map nickname is a synonym by which a NIS map can be referenced. If multiple keys are specified, the same map is searched for an occurrence of each key. A match is made only when the case and length of a key is the same as that stored in the database. No pattern matching is available. If a key is not matched, a diagnostic message is pro- duced. Options recognizes the following command-line options: Before printing the value associated with a key, print the key followed by a colon This option is useful if the keys are not part of the values (as in a map), or so many keys were specified that the output could be confusing. Inhibit the translation of a map's nickname to its corresponding mapname. For example, fails because there is no map named whereas, is translated to Specify a domain other than the default domain, that is, the one returned by (see domainname(1)). Display the nickname for each NIS map. AUTHOR
was developed by Sun Microsystems, Inc. SEE ALSO
domainname(1), ypcat(1), ypserv(1M), ypfiles(4). ypmatch(1)
All times are GMT -4. The time now is 11:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy