Linux learning sed maintains space

echo '1#sed#s' >> holdSpaceTest.txt
echo '2#deep#d' >> holdSpaceTest.txt
echo '3#good#g' >> holdSpaceTest.txt
echo '4#hood#h' >> holdSpaceTest.txt

Write the following content into it holdSpaceTest.txt:

1#sed#s
2#deep#d
3#good#g
4#hood#h

insert image description here

tac holdSpaceTest.txtYou can output the content in reverse, and note that tacthe command is catthe reverse of the command.
insert image description here

Next, we use sedthe holding space to implement the function of reverse output content.

hcopy pattern space to hold space append
Hpattern space to hold space copy
ghold space to pattern space append hold
Gspace to pattern space
xswap contents of pattern space and hold space

sed -n '1h;1!G;$!x;$p' holdSpaceTest.txtContent can be output in reverse.
insert image description here
The above operation is shown in the figure below:
insert image description here

sed -n '1!G;h;$p' holdSpaceTest.txtContent can be output in reverse.
insert image description here

The above operation is shown in the figure below:insert image description here

This article is a study note for Day 12 in August, and the content comes from Geek Time "100 Lectures on Linux Practical Skills" .

Guess you like

Origin blog.csdn.net/qq_42108074/article/details/132246334