文件中的重试特定值
我有一个文件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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基于您给定的示例:
/withName/{colles(f); f = $ 3“ .txt”}
如果行包含withname
,请使用第三个字段将文件名保存在f
中。CLOSS()
将关闭任何先前的文件句柄/file/{sub(/.* \//,“”); \。txt“。
f
中的文件名>>
而不是>
Based on your given sample:
/withName/{close(f); f=$3 ".txt"}
if line containswithName
, save filename inf
using the third field.close()
will close any previous file handle/file/{sub(/.*\//, ""); sub(/\.txt".*/, "");
if line containsfile
, remove everything except the value requiredprint > f
print the modified line and redirect to filename inf
>>
instead of>
这是尴尬中的解决方案:
/withName/{name = $ 3}
:当我看到包含“ withname”的行时,Here is a solution in awk:
/withName/{name=$3}
: when I see the line containing "withName", I save that name