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.
我从一个 shell 脚本中得到一个输入,比如:
USER1_OLD:USER1_NEW,USER2_OLD:USER2_NEW ....
密钥对的数量可以变化。我需要得到如下输出:
USER1_OLD,USER2_OLD,......
一种使用方式awk:
awk
$ ./script.sh | awk '{printf "%s",NR==1?$1:","$1}' FS=: RS=, USER1_OLD,USER2_OLD
不清楚您是否想要尾随逗号,如果您这样做,脚本可以更简单:
$ ./script.sh | awk '{print $1}' FS=: RS=, ORS=, USER1_OLD,USER2_OLD,