我有一个我在Cygwin中执行的shell脚本(也许这就是问题所在).对于这段代码,我只想写第一行,并附加一个换行符:
echo "`date` User `whoami` started the script." >> output.log
echo >> output.log
Run Code Online (Sandbox Code Playgroud)
但是output.log文件似乎永远不会中断.如果我多次运行脚本,就好像第二个echo没有写入文件.
我也尝试过:
echo -e "`date` User `whoami` started the script.\n" >> output.log
Run Code Online (Sandbox Code Playgroud)
它产生相同的结果.
奇怪的是,如果我只是在命令行上输入上面的第二个echo语句,而不附加到文件,它会给我带有尾随换行符的预期输出.
在我的shell脚本中,我试图使用$ sourcefile中找到的术语一遍又一遍地搜索相同的$ targetfile.
我的$ sourcefile格式如下:
pattern1
pattern2
etc...
Run Code Online (Sandbox Code Playgroud)
我必须搜索的低效循环是:
for line in $(< $sourcefile);do
fgrep $line $targetfile | fgrep "RID" >> $outputfile
done
Run Code Online (Sandbox Code Playgroud)
我知道可以通过将整个$ targetfile加载到内存中,或者使用AWK来改进这一点吗?
谢谢