The text consists of rows into columns

 

Today, a colleague asked me how to convert a row, the first idea is to use sed, but because sed is line editor, the following


ls -1 | sed -e "s / \ n / / g"

does not take effect.

Then I told him the content to be processed into the first vi inside, and then connected or J:% s / \ n / / g process.
Later he told me this is not cool (his words), and thus help google, g to the command:

LS -1 | TR -s '\ the n-' ''
So even if the task is complete, carefully looked at tr, found he is a character processing tool, something that can be achieved with basic sed can achieve.
Then again studied about how conversion Sed:

LS -1 | Sed -ne "H; $ {X; S / \ n-/ / G; P}"

Compared to the slightly more complicated point tr, H represents the pattern space of to append to the hold space, H can take an address, here is $, showing the end of the file,
then it will get into x in pattern space, the \ n reprinting can be replaced by a space.

Here with ls -1 as the input of this demonstration program, if multiple file columns, make columns into rows how to do it? Then you can use awk taken every column, and then the above method of treatment
can be.

Reproduced in: https: //www.cnblogs.com/FrankTan/archive/2010/03/23/1692831.html

Guess you like

Origin blog.csdn.net/weixin_34137799/article/details/93507727