1

How to skip the first line to print columns in some format and after some arithmetic operation below? Is it possible with next?

Input

#filename
4e+06 5e+06 6e+06 
5e+06 5e+06 6e+06

Code:

BEGIN { CONVFMT="%0.17f" }
function t(n, s) {
s=index(n,".")
return (s ? substr(n,1,s+2) : n)
}
FR>1 {print t($1-1000),t($2)}
  • 1
    Simply put a getline in the BEGIN block and it will skip the first line. – mosvy Feb 6 at 5:02
  • Where excatly to place it? What I tried is syntax error or it doesn't print the first line and don't count then. – Lukáš Altman Feb 6 at 5:07
  • You will see that a lot of people write NR != 1 {...} or such, and you'll probably receive answers like that; don't do it -- it's dumb ;-). If you want to skip the first line of each file, write FNR>1 && (...your condition...) { ... } – mosvy Feb 6 at 5:07
  • BEGIN { getline; CONVFMT="%0.17f" } – mosvy Feb 6 at 5:08
  • I got an empty file. – Lukáš Altman Feb 6 at 5:13
0

You just made a typo in the last line of your awk script: It should read FNR instead of FR in the address:

BEGIN { CONVFMT="%0.17f" }

function t(n, s) {
   s=index(n,".")
   return (s ? substr(n,1,s+2) : n)
}

FNR>1 {print t($1-1000),t($2)}

This works here as expected.

With the typo, the address FR>1 does not match any of your data lines: FR is a constant and the condition FR>1 always false. That's why you do not get any output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.