bash shell cut 命令删除字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6974769/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
shell cut command to remove characters
提问by acctman
The current code below the grep & cut is outputting 51315123&category_id, I need to remove &category_idcan cutbe used to do that?
grep & cut 下面的当前代码正在输出51315123&category_id,我需要删除&category_id可以使用cut来做到这一点吗?
... | tr '?' '\n' | grep "^recipient_dvd_id=" | cut -d '=' -f 2 >> dvdIDs.txt
回答by Owen
Yes, I would think so
是的,我会这么认为
... | cut -d '&' -f 1
回答by brightlancer
If you're open to using AWK:
如果您愿意使用 AWK:
... | tr '?' '\n' | awk -F'[=&]' '/^recipient_dvd_id=/ {print }' >> dvdIDs.txt
AWK handles the regex and splitting fields, in this case using both '=' and '&' as field separators and printing the second column. Otherwise, you will need a second cutstatement.
AWK 处理正则表达式和拆分字段,在这种情况下,使用 '=' 和 '&' 作为字段分隔符并打印第二列。否则,您将需要第二个cut语句。

