尽管使用该-c
选项进行剪切可用于大多数实际目的,但我认为将历史记录传送到awk将是更好的解决方案。例如:
history | awk '{ $1=""; print }'
要么
history | awk '{ $1=""; print $0 }'
这两种解决方案都做同样的事情。历史记录的输出被馈送到awk。然后,Awk会清空第一列,该列与历史命令输出中的数字相对应。在这里awk更方便,因为您不必担心输出数字部分中的字符数。
print $0
等价于print
,因为默认设置是打印行中显示的所有内容。键入print $0
更为明确,但是您可以选择哪种。的行为print $0
,只是print
使用awk使用时,如果使用AWK打印文件时更加明显(cat
会更快输入,而不是awk的,但是这是说明点)。
[Ex]使用awk显示$ 0的文件的内容
$ awk '{print $0}' /tmp/hello-world.txt
Hello World!
[Ex]使用awk显示文件内容而无需显式$ 0
$ awk '{print}' /tmp/hello-world.txt
Hello World!
[Ex]当历史记录行跨越多行时使用awk
$ history
11 clear
12 echo "In word processing and desktop publishing, a hard return or paragraph break indicates a new paragraph, to be distinguished from the soft return at the end of a line internal to a paragraph. This distinction allows word wrap to automatically re-flow text as it is edited, without losing paragraph breaks. The software may apply vertical whitespace or indenting at paragraph breaks, depending on the selected style."
$ history | awk ' $1=""; {print}'
clear
echo "In word processing and desktop publishing, a hard return or paragraph break indicates a new paragraph, to be distinguished from the soft return at the end of a line internal to a paragraph. This distinction allows word wrap to automatically re-flow text as it is edited, without losing paragraph breaks. The software may apply vertical whitespace or indenting at paragraph breaks, depending on the selected style."
cat ~/.bash_history
要排除在外?