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.
我对posix有点陌生,我不能使用:sed '1~2p'
sed '1~2p'
我的目标是跳过第一行的每一行:
1 2 3 4
会成为
1 3
我想知道 posix 的等价物是什么~。
~
更简单、便携的解决方案是:
awk 'NR%2' file
bash解决方案:
bash
while read -r line; do [ $((i++ % 2)) -eq 0 ] && echo "$line"; done < file
sed的代码:
sed -e n -e d file
或者:
sed -e 'n;d' file