文件中的重试特定值

发布于 2025-01-21 06:20:49 字数 952 浏览 2 评论 0原文

我有一个文件test.cf包含:

   process {

        withName : teq {

            file = "/path/to/teq-0.20.9.txt"

        }

    }

   process {

        withName : cad {

            file = "/path/to/cad-4.0.txt"

        }

    }

   process {

        withName : sik {

            file = "/path/to/sik-20.0.txt"

        }

    }

我想在teq,cad和sik的文件末尾关联的重新值

我首先在考虑类似的东西

grep -E 'teq' test.cf

,然后仅获得第二个原始的内容,然后在排队中删除一部分复发的

部分这样做可能更容易:(

for a in test.cf
do 
line=$(sed -n '{$a}p' test.cf)

if line=teq
#next line using sed -n?
    do print nextline &> teq.txt
else if line=cad
    do print nextline &> cad.txt
else if line=sik
    do print nextline &> sik.txt
done

显然它不起作用)

编辑:

输出想要: teq.txt包含teq-0.20.9,cad.txt包含cad-4.0 and sik.txt包含sik-20.0

有很好这样做的方式?谢谢你的评论

I have a file test.cf containing:

   process {

        withName : teq {

            file = "/path/to/teq-0.20.9.txt"

        }

    }

   process {

        withName : cad {

            file = "/path/to/cad-4.0.txt"

        }

    }

   process {

        withName : sik {

            file = "/path/to/sik-20.0.txt"

        }

    }

I would like to retreive value associated at the end of the file for teq, cad and sik

I was first thinking about something like

grep -E 'teq' test.cf

and get only second raw and then remove part of recurrence in line

But it may be easier to do something like:

for a in test.cf
do 
line=$(sed -n '{$a}p' test.cf)

if line=teq
#next line using sed -n?
    do print nextline &> teq.txt
else if line=cad
    do print nextline &> cad.txt
else if line=sik
    do print nextline &> sik.txt
done

(obviously it doesn't work)

EDIT:

output wanted:
teq.txt containing teq-0.20.9, cad.txt containing cad-4.0 and sik.txt containing sik-20.0

Is there a good way to do that? Thank you for your comments

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

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

发布评论

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

评论(2

孤芳又自赏 2025-01-28 06:20:49

基于您给定的示例:

awk '/withName/{close(f); f=$3 ".txt"}
     /file/{sub(/.*\//, ""); sub(/\.txt".*/, "");
            print > f}' ip.txt
  • /withName/{colles(f); f = $ 3“ .txt”}如果行包含withname,请使用第三个字段将文件名保存在f中。 CLOSS()将关闭任何先前的文件句柄
  • /file/{sub(/.* \//,“”); \。txt“。
  • sub( / 修改线,并重定向到f中的文件名
    • 如果您可以有多个条目,请使用>>而不是>

Based on your given sample:

awk '/withName/{close(f); f=$3 ".txt"}
     /file/{sub(/.*\//, ""); sub(/\.txt".*/, "");
            print > f}' ip.txt
  • /withName/{close(f); f=$3 ".txt"} if line contains withName, save filename in f using the third field. close() will close any previous file handle
  • /file/{sub(/.*\//, ""); sub(/\.txt".*/, ""); if line contains file, remove everything except the value required
  • print > f print the modified line and redirect to filename in f
    • if you can have multiple entries, use >> instead of >
卷耳 2025-01-28 06:20:49

这是尴尬中的解决方案:

awk '/withName/{name=$3} /file =/{print $3 > name ".txt"}' test.cf
  • /withName/{name = $ 3}:当我看到包含“ withname”的行时,
  • 当我看到“ file =”的行时,我保存该名称,我打印

Here is a solution in awk:

awk '/withName/{name=$3} /file =/{print $3 > name ".txt"}' test.cf
  • /withName/{name=$3}: when I see the line containing "withName", I save that name
  • When I see the line with "file =", I print
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文