我知道在Linux上我可以使用cat
从头到尾打印一个文件中的所有内容。有没有办法向后做(最后一行先做)?
发布于 2013-02-17 21:25:40
sed '1!G;h;$!d' file
sed -n '1!G;h;$p' file
perl -e 'print reverse <>' file
awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--] }' file
发布于 2013-02-17 21:03:29
可以,您可以使用tac命令。
来自man tac:
Usage: tac [OPTION]... [FILE]...
Write each FILE to standard output, last line first.
With no FILE, or when FILE is -, read standard input.
Mandatory arguments to long options are mandatory for short options too.
-b, --before attach the separator before instead of after
-r, --regex interpret the separator as a regular expression
-s, --separator=STRING use STRING as the separator instead of newline
--help display this help and exit
--version output version information and exit
发布于 2013-02-17 21:07:28
tac
是一种方法,但并非在所有linux上都默认可用。
awk可以这样做:
awk '{a[NR]=$0}END{for(i=NR;i>=1;i--)print a[i]}' file
https://stackoverflow.com/questions/14926024
复制相似问题