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.
私はすでに次のsedコマンドを使用して特定の単語 (たとえば A) で始まる行を印刷していますが、このコマンドを使用して A または B で始まる行を印刷する方法がわかりませんでした。
sed
sed -n '/A/p' 1.txt > 2.txt
代替案を追加するだけです:
sed -n '/A\|B/p' 1.txt > 2.txt
これは、A または B で始まる行だけでなく、A または Bを含む行も出力することに注意してください。行頭で実際に一致させるには、アンカーを追加する必要があります^。
^
sed -n '/^A\|^B/p' 1.txt > 2.txt
これはと同等です
sed '/^A\|^B/!d' 1.txt > 2.txt
これは、「AまたはBで始まらない行を削除する」ことを意味します。