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!

awk and array

Status
Not open for further replies.

Rdave

Programmer
Oct 24, 2002
3
US
Hi all,

I am new to awk command I have the following input file:

rashmi:xyz@1234:zyx:1234;
prashant:xyz@2345:zyx:2345;

and I would like the output in this format:

rashmi prashant
xyz@1234 xyz@2345
zyx zyx
1234 2345

any ideas how to achive using awk.

I have managed to produce

rashmi
xyz@1234
zyx
1234

prashant
xyz@2345
zyx
2345

thanks in advance
 
something like that:

nawk -f columns.awk file.txt

#----------------- columns.awk
BEGIN {
FS=":|;"
}

{
for(i=1; i < NF; i=i+2) {
names[i, FNR]=$i
values[i, FNR]=$(i+1)
}
columns=int(i/2);
}

END {
for(i=1; i <= FNR*columns; i=i+columns) {
for(j=1; j <= columns; j++)
printf(&quot;%s\t&quot;, names[i,j] );
print &quot;&quot;
for(j=1; j <= columns; j++)
printf(&quot;%s\t&quot;, values[i,j] );
print &quot;&quot;
}
}
vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top