例如我有一个文件:
$ cat file i am the first example. i am the second line. i do a question about a file.
我需要:
example, line, file
我打算使用“ awk”,但问题是单词在不同的空间
尝试
$ awk 'NF>1{print $NF}' file example. line. file.
要像您的示例一样在一行中获得结果,请尝试:
{ sub(/\./, ",", $NF) str = str$NF } END { print str }
输出:
$ awk -f script.awk file example, line, file,
纯重击:
$ while read line; do [ -z "$line" ] && continue ;echo ${line##* }; done < file example. line. file.