텍스트에서 URL 가져오기

텍스트에서 URL 가져오기

텍스트 파일에서 제공한 URL을 사용하여 모든 패키지를 다운로드하려는 텍스트 파일을 얻었습니다 apt-get --print-uris dist-upgrade > /mnt/URIs.txt. '' 사이의 텍스트만 URL입니다. URL과 반환 기호만 사용되므로 나머지는 어떻게 제거할 수 있습니까? 인터넷 브라우저를 통해 다운로드 중입니다.

답변1

가능한 출력은 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://작은따옴표 앞에서 시작하고 끝나는 모든 하위 문자열을 일치시키려고 시도합니다 . 그런 다음 전체 줄을 해당 하위 문자열로 바꾸고 수정된 줄을 인쇄합니다. 일치하지 않는 행은 삭제됩니다.

관련 정보