如何在Linux上反向读取文件?
我知道我可以使用如何在Linux上反向读取文件?,linux,cat,Linux,Cat,我知道我可以使用cat在Linux上从头到尾打印文件中的所有内容。 有没有办法向后(最后一行在前)?是的,您可以使用“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 ar
cat
在Linux上从头到尾打印文件中的所有内容。
有没有办法向后(最后一行在前)?是的,您可以使用“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
tac
是一种方式,但并非所有linux上都默认可用
awk可以这样做:
awk '{a[NR]=$0}END{for(i=NR;i>=1;i--)print a[i]}' file
sed'1!Gh、 美元!d'文件
sed-n'1!Gh$p'文件
perl-e“打印反向”文件
awk'{a[i++]=$0}END{for(j=i-1;j>=0;)打印[j-->}文件
你所说的“阅读”是什么意思?具体说明文件的内容以及您期望的“向后”结果是什么样子。我想查看2gb文件的结尾,所有2gb都在一行上,所以我做了这个“dd if=file.xml ibs=1 skip=2049186000 count=100”-意思是从2049186000位置开始读取100字节。输出中有一些dd内容,但它完成了任务。
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