有这些行:
[2022-04-14T20:06:17+0800] [ALPM] installed data (0.5.0-7)
[2022-04-14T20:06:17+0800] [ALPM] installed data-cleo (0.4.1-4)
[2022-04-14T20:06:17+0800] [ALPM] installed python (0.2.2-11)
只想获取包并用空格而不是换行符分隔:
data data-cleo python
答案1
既然你标记了你的问题linux
,我假设你有 GNU grep 及其-P
PCRE 选项。然后
$ grep -Po 'installed\s+\K\S+' log.txt | paste -sd ' '
data data-cleo python
答案2
使用任何 awk:
$ awk '$3=="installed"{ printf "%s%s", sep, $4; sep=OFS } END{ print "" }' file
data data-cleo python
答案3
答案如下。
cat log.txt | sed -n 's/.*installed //p' | sed 's/ (.*//p' | tr '\n' ' '