i am trying to
insert text at the beginning of every even number line
with awk
i can do it with odd number lines
with this command
awk 'NR%2{$0="some text "$0}1' file
how can i edit this command
thanks
i am trying to
insert text at the beginning of every even number line
with awk
i can do it with odd number lines
with this command
awk 'NR%2{$0="some text "$0}1' file
how can i edit this command
thanks
Do you mean something like:
awk 'NR%2 == 1{$0="some text "$0}1' file
thanks for reply
i changed the == 1 to 2==0
now it works many thanks great forum
awk 'NR%2==0{$0="some text "$0}1' file
Ouch. Yes. Sorry. I wasn't paying close enough attention.
I'm glad you got it to work.
Or you may use negation in your original command as follows:
awk '!NR%2{$0="some text "$0}1' file
Not quite. In awk !
has higher precedence than %
so that evaluates as (!NR)%2
. But:
awk '!(NR%2){$0="some text "$0}1' file
would work.