我正在尝试使用cut -c-2-18- filename
. 这会在每一行上剪切指定字符,但我只想从以>
.
问问题
1733 次
3 回答
1
就像是
grep ^\> file | cut -c 2-18
应该做的伎俩?
[92][11:46:21] vlazarenko@alluminium (~/tests) > grep ^\> file | cut -c 2-18
asdf
bcda
ofpjg
[93][11:46:25] vlazarenko@alluminium (~/tests) > cat file
> asdf
> bcda
zxcv
lasdf
> ofpjg
于 2013-02-26T10:45:11.357 回答
1
您可以GNU grep
单独执行此操作:
$ cat file
>grep from 2 to 18 character line 1
>grep from 2 to 18 character line 2
grep from 2 to 18 character line 3
grep from 2 to 18 character line 4
$ grep -Po '(?<=^>).{17}' file
grep from 2 to 18
grep from 2 to 18
这使用正向lookbehind仅匹配以开头的行>
并.{17}
匹配接下来的 17 个字符。
或与awk
:
$ awk '/^>/{print substr($0,2,18)}' file
grep from 2 to 18
grep from 2 to 18
于 2013-02-26T10:51:13.580 回答
1
awk '/^\>/{print substr($0,2,17)}' your_file
于 2013-02-26T11:00:52.943 回答