I have a file with n number of cols. I need to modify the size of each field. it may be either increase or decrease the present size of the field.
can anybody help me in this plz
thanks in advance
I have a file with n number of cols. I need to modify the size of each field. it may be either increase or decrease the present size of the field.
can anybody help me in this plz
thanks in advance
U may try something like :
1) Awk '{printf (substr($0,m,n)" "substr($0,x,y)\n) }' <file> to select the fields as ur need.
2) or awk '{printf "%s\t%d"\n,$1,$2) <file>
Try...
awk ' {
for(x=1; x<=NF; x++) {
a[NR, x] = $x
if (length($x) > ma[x])
ma[x] = length($x)
}
if (NF > cm)
cm = NF
}
END {
for (y=1; y<=NR; y++)
for (x=1; x<=cm; x++)
printf ("%" ($x~/[A-Za-z]/?"-":"") ma[x] "s" (x==cm?ORS:OFS)), a[y,x]
}' file1 > file2
thanks for the code. Can u plz explain me the code?
Which part don't you understand?