0

I want to move several lines to the end of the file.

Example:

1
2
3
4
5
6 blkn XYZ indf
7
8
9
10
11 lnkn ABCYDF knnfd
12
13
14
15

I want to move lines 6 to 11 to the end of the file. The patterns are XYZ for the beginning line and ABC* for the last line.

I managed already to copy them via awk '/XYZ/,/ABC*/ {print}' file >> file to the end of the file.

I don't know how to move these lines to the end, maybe some of you have an elegant solution for this.

2

You are pretty close already. Just save the lines in some variable and use an END rule to print it:

/XYZ/, /ABC.*/ { result = result $0 RS; next }
{print}
END { print result }

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.