0

If the next line is b, I want to add it to the AA line.

This is my file:

AA b b AA b AA b b b 

Desired output:

AA b b AA b AA b b b 

The below is the code I am trying.

paste -s -d" " file.txt | awk '{for(i=1;i<=NF;i++){if(i > 1 && $i == "AA")????}}' 

I printed several line in one line and tried to run for loop to the last field and go down to the next line if $i is AA. But I do not know what to do after the 'if' statement.

Can anyone help me?

0

1 Answer 1

1

POSIXLY:

sed -ne ' /^AA$/b1 :1 $!N /\nb$/s/\n/ / t1 P;D ' <file 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.