如何使用 bash 脚本将一个 txt 文件到另一个 txt 文件的链接放置在特定位置?

发布于 2025-01-17 02:54:27 字数 1067 浏览 1 评论 0原文

我有一个 css 文件,即 1.css

/* CSS variables
   Generated by 'wal' */
:root {
**    --wallpaper: url("/home/x/.local/share/wallpaper/wall.png");**

    /* Special */
    --background: #10171d;
    --foreground: #daccd3;
    --cursor: #daccd3;

我想提取壁纸 url“”中的 url 链接。并想将其放入这个 css 文件中,即

@-moz-document url(about:home), url(about:newtab), url(about:privatebrowsing) {
    .click-target-container *, .top-sites-list * {
        color: #fff !important ;
        text-shadow: 2px 2px 2px #222 !important ;
    }
 
    body::before {
        content: "" ;
        z-index: -1 ;
        position: fixed ;
        top: 0 ;
        left: 0 ;
        **background: #f9a no-repeat url("want to put that link here") center ;**
        background-size: cover ;
        width: 100vw ;
        height: 100vh ;
    }
}

我希望链接位于第二个 css 文件的后台 url 中,

我尝试了一些命令

awk 'NR==4 { print $2 }' colors.css > 1.txt
cat '1,txt' |sed 's/;.*//' > 2.txt

来从第一个文件中提取链接。但我不知道如何将该链接导入到第二个 css 文件的确切位置

I have a css file which is this 1.css

/* CSS variables
   Generated by 'wal' */
:root {
**    --wallpaper: url("/home/x/.local/share/wallpaper/wall.png");**

    /* Special */
    --background: #10171d;
    --foreground: #daccd3;
    --cursor: #daccd3;

I want to extract that url link which is in wallpaper url " ". and want to put it in this css file which is this

@-moz-document url(about:home), url(about:newtab), url(about:privatebrowsing) {
    .click-target-container *, .top-sites-list * {
        color: #fff !important ;
        text-shadow: 2px 2px 2px #222 !important ;
    }
 
    body::before {
        content: "" ;
        z-index: -1 ;
        position: fixed ;
        top: 0 ;
        left: 0 ;
        **background: #f9a no-repeat url("want to put that link here") center ;**
        background-size: cover ;
        width: 100vw ;
        height: 100vh ;
    }
}

I want the link to be in background url of the 2nd css file

I tried some of this commands

awk 'NR==4 { print $2 }' colors.css > 1.txt
cat '1,txt' |sed 's/;.*//' > 2.txt

to extract the link from first file. But I don't know how to import that link to the 2nd css file at the exact place

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜未央樱花落 2025-01-24 02:54:27

awk 结果放入变量中。然后在 sed 中使用该变量来更新 CSS 文件。

url=$(awk '/--wallpaper:/ {print($2)}' colors.css)
sed -E -i '/background:/s#(background: .* )url\([^)]*\)(.*;)#\1'"${url%;}"'\2#' second.css

% 参数扩展运算符可用于删除 $url 中尾随的 ;

Put the awk result in a variable. Then use that variable in sed to update the CSS file.

url=$(awk '/--wallpaper:/ {print($2)}' colors.css)
sed -E -i '/background:/s#(background: .* )url\([^)]*\)(.*;)#\1'"${url%;}"'\2#' second.css

The % parameter expansion operator can be used to remove the trailing ; in $url.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文