Hello, I am having an odd problem with awk. Here is my script:
Code:
gawk --source='
/^#/ {next}
/^$/ {next}
/^+/ {file = $1
print "file: " $file
for ( x=2; x <= NF; ++x ) {
print x $x
}
next}
{print}' $SOURCE_FILE > $INCLUDE_FILE
}
My source file is a file with # -delimited comments, so the awk program ignores lines beginning with # and blank lines. The next part is supposed to look for lines beginning with '+' and then print just the first field. If I do
, I get just the first field, but if I try to assign $1 to another variable, or use any function on it to assign it (such as sub or split), I get $0 instead - the entire line. I want to process the line and remove the leading '+' so I get just the file name.
What gives?
Also, what's an easy way to compare just the first character of an awk field, so I can check if the first character is a +, a -, or a (?
Thanks for your help.