Here are 3 awk questions I found on that site.
----------------------------------------------------------
echo "$names"
The outout of this is JOHN,MIKE,EAGLES,SCOTT,MIKE1,JOHN2.....................etc like these names (70 names in a single line)
I am getting the below error if i execute the below line with the above names
var1=`echo "$names" | awk -F, '{print NF}'`
awk: record `JOHN,MIKE,EAGLES,SCOTT,MIKE1,JOHN2........................' too long
------------------------------------------------------
Probably needs to use nawk.
------------------------------------------------------
Suppose I have a following file "tmpFile" :
'1111,aaa '
'2222,bbbb '
excluding single quotes, those I have shown in order to signify the presence of
trailing spaces at the end of the record.
Now if I run following command,
awk -F"," '{printf("%s:%s\n", $1,$2) }' tmpFile
$2 field is read as-
'aaa '
'bbbb '
Actually at the time of reading, I would like to read as -
'aaa'
'bbbb'
----------------------------------------------------------
The solution given was:
Code:
awk -F',' '{gsub(/[\t ]*$/,"",$2);print $2}' datafile
sub(), not gsub(), should be used since only 1 match is being replaced. [\t ]* should be
[\t ]+ since * means 0 or more occurrances; if there are 0 occurrances, there's nothing to replace.
And since the spaces are at the end of the line, this would do: [tt]sub(/[\t ]+$/,"")[/tt]
-----------------------------------------------------
Fred Smith and Sue Brown
Joe Jones and Jane Watts
Sally Green and Jim O?
Connor
Freda O?
Reiley and Pat O?
Connell
Peter Parker and Tina Williams
need to be changed to
Fred Smith and Sue Brown
Joe Jones and Jane Watts
Sally Green and Jim O?Connor
Freda O?Reiley and Pat O?Connell
Peter Parker and Tina Williams
----------------------------------------------------
The solution was
Code:
{ if ( $0 ~ /\?$/ ) {
line=line$0;
next;
} else {
print line$0;
}
line="";
}
Too long, and he thinks Awk is C (semicolons everywhere).
Code:
/\?$/ { line = line $0; next }
{ print line $0; line = "" }