awk: changing OFS without looping though variables -


i'm working on awk one-liner substitute commas tabs in file ( , swap \\n missing values in preparation mysql select into).

the following link http://www.unix.com/unix-for-dummies-questions-and-answers/211941-awk-output-field-separator.html (at bottom) suggest following approach avoid looping through variables:

 echo b c d | awk '{gsub(ofs,";")}1'   head -n1 flatfile.tab | awk -f $'\t' '{for(j=1;j<=nf;j++){gsub(" +","\\n",$j)}gsub(ofs,",")}1' 

clearly, trailing 1 (can number, char) triggers printing of entire record. please explain why working?

so has print fields awk separated ofs , in post seems unclear why working.

thanks.

awk evaluates 1 or number other 0 true-statement. since, true statements without action statements part equal { print $0 }. prints line.

for example:

$ echo "hello" | awk '1' hello $ echo "hello" | awk '0' $ 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -