简体   繁体   English

shell cut命令用于删除字符

[英]shell cut command to remove characters

grep的&切低于当前代码输出51315123&category_id ,我需要删除&category_id可以减少被用来做呢?

... | tr '?' '\n' | grep "^recipient_dvd_id=" | cut -d '=' -f 2 >> dvdIDs.txt

是的,我会这么认为

... | cut -d '&' -f 1

If you're open to using AWK: 如果您愿意使用AWK:

... | tr '?' '\n' | awk -F'[=&]' '/^recipient_dvd_id=/ {print $2}' >> dvdIDs.txt

AWK handles the regex and splitting fields, in this case using both '=' and '&' as field separators and printing the second column. AWK处理正则表达式和拆分字段,在这种情况下使用'='和'&'作为字段分隔符并打印第二列。 Otherwise, you will need a second cut statement. 否则,您将需要第二个cut声明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM