Nik*_*sov 6 grep text-processing
我有一堆文件,它们都遵循相同的数据模式。
假设这是我想要从中提取的模式:
First part of text...patternA......Second part of text.....patternB.....Third part of text....patternC.....End part of text
目前我正在使用这个:
grep -P -o ".{0,5}patternA|.{0,5}patternB.{0,5}|patternC.{0,5}" filename.txt
这样我得到的输出是:
1111 patternA
2222 patternB 2222
patternC 3333
Run Code Online (Sandbox Code Playgroud)
我真正想要的输出是:
1111 patternA 2222 patternB 2222 patternC 3333
我似乎无法弄清楚如何摆脱每个模式末尾的换行符。
我怎样才能做到这一点?
和column
:
COLUMN(1) BSD General Commands Manual COLUMN(1)
NAME
column -- columnate lists
SYNOPSIS
column [-tx] [-c columns] [-s sep] [file ...]
DESCRIPTION
The column utility formats its input into multiple columns. Rows are
filled before columns. Input is taken from file operands, or, by
default, from the standard input. Empty lines are ignored.
Run Code Online (Sandbox Code Playgroud)
例如(通过免费无用的使用cat
来证明您可以将 的grep
输出通过管道传输到column
):
$ cat example
Fuzzy
wuzzy
was
a
bear
$ cat example | column
Fuzzy wuzzy was a bear
Run Code Online (Sandbox Code Playgroud)