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
tac holdSpaceTest.txt
You can output the content in reverse, and note that tac
the command is cat
the reverse of the command.
Next, we use sed
the holding space to implement the function of reverse output content.
h
copy pattern space to hold space append
H
pattern space to hold space copy
g
hold space to pattern space append hold
G
space to pattern space
x
swap contents of pattern space and hold space
sed -n '1h;1!G;$!x;$p' holdSpaceTest.txt
Content can be output in reverse.
The above operation is shown in the figure below:
sed -n '1!G;h;$p' holdSpaceTest.txt
Content can be output in reverse.
The above operation is shown in the figure below:
This article is a study note for Day 12 in August, and the content comes from Geek Time "100 Lectures on Linux Practical Skills" .