Hi,
Can someone let me know if the below AWK can be made much simpler / efficient ?
I have 200 fields, I need to substr only the last fields.
So i'm printing awk -F~ 'print {$1, $2, $3....................................$196,$197 , susbstr($198,1,3999), substr($199,1,3999)..}'
Is there a way we can rewritten ??
Thnx
By efficient I think you mean readable
awk -F~ '{ for(i=1;i<198;i++){
printf("%s ", $i);
}
for(i=198;i<NF;i++){
printf("%s ", substr($i,1,3999);
}
printf("%s\n", $NF);
}' someinputfile
Most awks cannot read lines longer 2048 bytes, so I don't get the substr($199,1,3999)
part....
edit per vgersh99
braindrain,
how many of 'last' fields do you need to operate on?
jim,
NR != NF
Vgersh,
I have last 3 fields to be operated upon.
Also, If AWK / other stream editors cannot operate on string of 4000, is there an alternative that we can use. I have a continous string of 4500, due to limitation in oracle which can stroe 4000, I would like to trim it forehond.
there were some discussion in this forum not very decisive, so I had open a thread, sorry.
nawk -F~ -v OFS='~' '{
for(i=(NF-3);i<=NF;i++){
$i = substr($i,1,3999);
$1=$1; print
}' someinputfile
if 'nawk' does break on your records and if you're on Sun/Solaris try '/usr/xpg4/bin/awk' OR if you have 'gawk' installed on your system - try it.