
によってテキスト ファイルを取得しapt-get --print-uris dist-upgrade > /mnt/URIs.txt
、テキスト ファイルによって提供される URL を持つすべてのパッケージをダウンロードしたいのですが、 '' の間のテキストのみが URL です。インターネット ブラウザーによるダウンロードには URL とリターン記号のみが使用されるため、残りを削除する方法を教えてください。
答え1
mayからの出力はapt-get --print-uris dist-upgrade
次のようになります。
Reading package lists...
Building dependency tree...
Reading state information...
Calculating upgrade...
The following packages will be upgraded:
evolution-data-server evolution-data-server-common gir1.2-goa-1.0
gnome-online-accounts libcamel-1.2-62 libebackend-1.2-10 libebook-1.2-20
libebook-contacts-1.2-3 libecal-2.0-1 libedata-book-1.2-26
libedata-cal-2.0-1 libedataserver-1.2-24 libedataserverui-1.2-2
libgoa-1.0-0b libgoa-1.0-common libgoa-backend-1.0-1 libyelp0 linux-libc-dev
python-apt-common python3-apt yelp
21 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 4,358 kB of archives.
After this operation, 16.4 kB of additional disk space will be used.
'http://se.archive.ubuntu.com/ubuntu/pool/main/p/python-apt/python-apt-common_2.0.0ubuntu0.20.04.5_all.deb' python-apt-common_2.0.0ubuntu0.20.04.5_all.deb 17052 MD5Sum:a9e11f5f8671c5069f5edaef32e2f620
'http://se.archive.ubuntu.com/ubuntu/pool/main/p/python-apt/python3-apt_2.0.0ubuntu0.20.04.5_amd64.deb' python3-apt_2.0.0ubuntu0.20.04.5_amd64.deb 154164 MD5Sum:8590dd473b444f2756e5c7498e00e7ec
'http://se.archive.ubuntu.com/ubuntu/pool/main/g/gnome-online-accounts/libgoa-1.0-common_3.36.1-0ubuntu1_all.deb' libgoa-1.0-common_3.36.1-0ubuntu1_all.deb 3752 MD5Sum:9252da969452bdf88527829a752ac175
(この出力は切り捨てられています)
上記の「クリーンな」URI を解析すると仮定すると、次のsed
コマンドは、最初の行から文字列で始まる行までのすべての行を削除しますAfter
(文字列を含む)。残りの行からは、スペースの後のすべてを削除し、変更された行の最初と最後の文字を削除します (これにより、URI を囲む単一引用符が削除されます)。
sed '1,/^After/d; s/ .*//; s/.//; s/.$//'
これを上記の短い出力例に使用します。
$ sed '1,/^After/d; s/ .*//; s/.//; s/.$//' file
http://se.archive.ubuntu.com/ubuntu/pool/main/p/python-apt/python-apt-common_2.0.0ubuntu0.20.04.5_all.deb
http://se.archive.ubuntu.com/ubuntu/pool/main/p/python-apt/python3-apt_2.0.0ubuntu0.20.04.5_amd64.deb
http://se.archive.ubuntu.com/ubuntu/pool/main/g/gnome-online-accounts/libgoa-1.0-common_3.36.1-0ubuntu1_all.deb
同じ入力データを与えると、コマンド
sed -n "s,.*\(http://[^']*\).*,\1,p" file
も動作します。これは、単一引用符で始まり、単一引用符の前で終わる部分文字列の一致を試みますhttp://
。次に、行全体をその部分文字列に置き換え、変更された行を出力します。一致しない行は破棄されます。