假设我有一个这样的文件:
foo bar foo bar foo bar foo bar something useful"foo bar foo bar"
Run Code Online (Sandbox Code Playgroud)
基本上,我想知道如何自己获取字符串something useful
,或者保存到自己的文件中,或者单独显示为输出。
总是会有之前相同的字符数(33)something useful
和总是会有"
后直接吧。
xhi*_*nne 13
尝试这个:
cut -c 34- | cut -d '"' -f1
Run Code Online (Sandbox Code Playgroud)
首先cut
删除前33个字符;secondcut
只保留 first 之前的部分"
。
这是grep
使用 perl 语法的GNU版本:
grep -oP '.{32}\K[^"]*'
Run Code Online (Sandbox Code Playgroud)
它 grep 前 32 个字符,将其切掉\K
并打印其余的直到 first "
。