Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
grep & cut 下面的当前代码正在输出51315123&category_id,我需要删除&category_id可以使用cut来执行此操作吗?
51315123&category_id
&category_id
... | tr '?' '\n' | grep "^recipient_dvd_id=" | cut -d '=' -f 2 >> dvdIDs.txt
是的,我会这么认为
... | cut -d '&' -f 1
如果您愿意使用 AWK:
... | tr '?' '\n' | awk -F'[=&]' '/^recipient_dvd_id=/ {print $2}' >> dvdIDs.txt
AWK 处理正则表达式和拆分字段,在这种情况下,使用 '=' 和 '&' 作为字段分隔符并打印第二列。否则,您将需要第二cut条语句。
cut