Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

header

Status
Not open for further replies.

ovince

Programmer
Feb 27, 2007
55
FR
Hi All,

I join 2 files matching columns like

awk 'BEGIN{FS=",";OFS=","}
NR==FNR{a[$1]=$1;b[$1]=$23;c[$1]=$44;next} $1 in a {print a[$1],$1,b[$1],c[$1], $2, $3, $4, $5}'
filq
e1.csv file2.csv > joined.csv

I have headers in file1.csv and file2,csv.How to keep corresponding headers in joined.csv file


thanks
oliver
 
Hi

Code:
awk '
BEGIN{FS=",";OFS=","}
[red]{v=FNR==1?"\n":$1}[/red]
NR==FNR{a[[red]v[/red]]=$1;b[[red]v[/red]]=$23;c[[red]v[/red]]=$44;next}
[red]v[/red] in a {print a[[red]v[/red]],$1,b[[red]v[/red]],c[[red]v[/red]], $2, $3, $4, $5}
'file1.csv file2.csv > joined.csv

Feherke.
 
thanks Feherke

And what to do in this case ... I want to write out some columns like:

awk 'BEGIN {FS=",";OFS=","}
/^#/{next} {print $58,1/($63*$63)}'
file.csv file > file1.csv

As you see, I skeep header because 1/($63*$63) operation would report error if I do not skeel it. But steel I would like to keep header in output file. I know that I should use similar logic as

{v=FNR==1?"\n":$1}

but any try failed so far (probably because I do not understand it in full detail)


thanks
oliver

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top