...but I want to keep the space between the successful words I do find and still preserve the newline.
Anotherword, I want the output from each line to appear on the same line, spearated by a space, with the last word having no space at the end of line.
My Input Data:
1dog 2dog 3bird
5dog 4bird 4dog
Desired Output:
1dog 2dog <--no space at end of line
5dog 4dog <--no space at end of line
awk '{for(i=1;i<=NF,++i)if($i ~/dog/)printf("%s ",$i);print""}'
I know there are different ways to put a space between each successful $i (i.e. - printf("%s$s", $i,OFS) ), but my problem is when the line is finished, I don't want the last space at end of each line.
how can I do this??
Anotherword, I want the output from each line to appear on the same line, spearated by a space, with the last word having no space at the end of line.
My Input Data:
1dog 2dog 3bird
5dog 4bird 4dog
Desired Output:
1dog 2dog <--no space at end of line
5dog 4dog <--no space at end of line
awk '{for(i=1;i<=NF,++i)if($i ~/dog/)printf("%s ",$i);print""}'
I know there are different ways to put a space between each successful $i (i.e. - printf("%s$s", $i,OFS) ), but my problem is when the line is finished, I don't want the last space at end of each line.
how can I do this??