ファイルからパターンの前後のテキストを削除する方法

ファイルからパターンの前後のテキストを削除する方法

単語が非常に長く、スペースもなく、行も多くのファイルがあります。

ファイル.txt:

data-number="210615"
...
.... 
....
1280654445itemitemURLhttps://site.site.com/user-user/fooo/210615/file.name.jpg?1280654445name......
...
...
...
...

#!/bin/bash
find_number=$(grep -Po 'data-number="\K[^"]*' file.txt)

get-url= (copy from "https" to "fooo/" and add variable $find_number and add from "/" to end "jpg"
maybe : get-url=("https*,*fooo/",$find-number,"/*.jpg") this is work or other idea?

echo $get-url  > result.txt

結果.txt:

https://site.site.com/user-user/fooo/210615/file.name.jpg

ベストアンサー1

grep数値抽出のコマンドに従ってください。

grep -Po "http.*?$find_number.*?\.jpg"

おすすめ記事