我需要提取字符 '(' 之前的字符。我的文件结构是:
玫瑰(好)好吧
雏菊()没有
礼来(坏)很好
向日葵()不错
我需要以下形式的输出文件:
rose
daisy
lilly
sunflower
Run Code Online (Sandbox Code Playgroud)
谁能告诉这个命令.....
awk、grep 或 sed 更可取...
使用cut
:
$ <file cut -d \( -f 1
rose
daisy
lilly
sunflower
Run Code Online (Sandbox Code Playgroud)
使用sed
:
$ <file sed -e 's/\(.*\)(.*$/\1/'
rose
daisy
lilly
sunflower
Run Code Online (Sandbox Code Playgroud)
解决方案awk
:
$ awk -F'(' '{print $1}' file
rose
daisy
lilly
sunflower
Run Code Online (Sandbox Code Playgroud)
或 GNU grep
:
grep -oP '.*?(?=\()' file
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
58519 次 |
最近记录: |