我有一个针对文件运行的脚本,它接受用户的参数,并通过grep和awk发送以获得所需的列。它将返回多行。我想要做的是通过grep\awk的输出读取(或类似的东西),并通过另一个脚本(./lookup)运行它。我的问题是如何循环每一行,并通过脚本中的脚本运行该行上的内容。希望这是有意义的,我对脚本和linux还不熟悉。
#!/bin/sh
x=$(grep "$*" "$c"|awk '{print $6}')
while read LINE
do
./lookup $x
done
这似乎是可行的,但只适用于输出的第一行。它还要求我按enter
我在linux中有一个文件,其中包含应用程序的日志。使用grep,我得到了想要的行,但我需要处理它们,以便只获得特定的值。更确切地说,我有下一个日志:
13 Jan 2014 15:22:18,291 DEBUG some data
13 Jan 2014 15:22:18,291 DEBUG some data
13 Jan 2014 15:22:18,291 DEBUG <request><object>3</object></request>
13 Jan 2014 15:22:18,291 DEBUG <request><
我试着用awk分割列来打印一个句子,但是第一个列有空格。
我的初学者代码示例:
$ awk '/Linux/ { print "The filename","\""$1"\"","is located in",$2 }' test.txt
The filename "The" is located in test
The filename "Some" is located in file
The filename "File" is located
我正在运行一个(相当最近的)基于Debian的发行版。
我想要生成一个与特定模式匹配的所有已安装软件包的简单列表。我可以通过跑步,比如说,
apt list --installed "linux-image-*" | cut -d/ -f1
但我有我不关心的台词,例如:
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
Listing...
所以也许我最好不要使用apt。我可以像这样运行dpkg查询:
dpkg-query --showformat='${Pa
在Python中,我想测试Linux命令的输出中是否存在关键字。要测试的关键字将作为列表传递,如下所示。我没有花太多的时间使用Python,所以下面是暴力破解的方法。有没有一种更干净的方式来写这篇文章? def test_result (result, mykeys):
hit = 0
for keyword in mykeys:
if keyword in result:
hit = 1
print "found a match for " + keyword
if hit == 1:
return Tru
我有一个文本文件,里面有很多带字母间距的行,例如
cat test.txt
Some word here: T h e Q u i c k B r o w n F o x J u m p s O v e r T h e L a z y D o g
Some doggerel: J a c k A n d J i l l W e n t U p T h e H i l l
我使用Linux中的一些命令行工具,要求将一些正则表达式应用于这个文本文件,以删除字符之间的空格。
cat result.txt
Some word here: The Quick Brown Fox Jumps Over T
我试图从字段$5中的相同记录中找到一个字符串模式,该字符串模式由单词结论和字段$2和字段$3的值组成。
例如,my_file.txt是由“AC.26”分隔的:
1|substance1|substance2|red|CONCLUSIONS: the effect of SUBSTANCE1 and SUBSTANCE2 in humans...|
2|substance3|substance4|red|Conclusions: Substance4 is not harmful...|
3|substance5|substance6|red|Substance5 interacts with