Click to See Complete Forum and Search --> : Format help, awk, tr??


Linux_cat
08-27-2007, 11:28 AM
hi guys i have a small problem that i want a little help with, i have a bunch of text files that hold data in the following format:

|-8|1
|-1|5
|-2|5
|-15|1
|-5|2


and i basically want to take the files and use the first columns as the headings with the second being the value e.g for the above example:


-8|-1|-2|-15|-5
1|5|5|1|2

whch unix/linux tool would complete this in the quickest way and how would i do it?

ghostdog74
08-28-2007, 04:58 AM
awk -F"|" '{ one[NR] = $2; two[NR] = $3 }
END {
for (i = 1; i <= NR; i++) {
printf("%s|", one[i])
}
print ""
for (i = 1; i <= NR; i++) {
printf("%s|", two[i])
}
print ""

}' file