Make a new field with a word on it

i have a file contains as below:
[file]:

12 32 qw
21 44 qq
###
11 90 er
88 23 sa
###

i want to add new field with constant string "madd" between 2nd field and 3rd field of each record, so the desired output will be:
[out]:

12 32 madda qw
21 44 madda qq
###
11 90 madda er
88 23 madda sa
###
awk 'NF-1{$3="madda " $3}1' file

Try This,

nawk '{if($0!~/###/){$3="madd " $3}}1' txt

Regards,
Indu.

 
$ nawk '!/^\#/{$2=$2" abcd"}1' test.txt
12 32 abcd qw
21 44 abcd qq
###
11 90 abcd er
88 23 abcd sa
###

@all: what about empty lines?

@Scrutinizer

The OP didn't provide empty lines in his/her example file :slight_smile:

Now, that is technically true :wink:

awk 'NF>2{$3="madda " $3}1' infile

what is the "1" at the end of the Brace { }" ?

1 (true) is used to execute the print statment

try the below two

 
nawk '1' input.txt
nawk '0' input.txt

stay without change

What is your OS and version?