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.
次の例のように、1行の長さの文字列を含むxmlファイルがあり、「」の後の数字を抽出したいので、131を取得したい
.....<yt:duration seconds='131'/>....
ここでの「....」は、「」の前後の部分文字列を意味します。これらの部分文字列は、文字、数字、マークが異なる長いものです。
一致する番号を抽出するためにsedを使用する方法は?ありがとう
sedソリューション(@区切り文字として使用):
@
sed -r "s@.*<yt:duration seconds='([0-9]+)'/>.*@\1@" file.txt
OSXの場合は、次のように置き換え-rます-E
-r
-E
grepではなく、を使用してくださいsed:
grep
sed
grep -o "<yt:duration seconds='[0-9]\+'/>" file.txt | cut -f2 -d"'"