Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 检查多行并输出缺少的行。(猛击)_Linux_Bash_Shell_Scripting - Fatal编程技术网

Linux 检查多行并输出缺少的行。(猛击)

Linux 检查多行并输出缺少的行。(猛击),linux,bash,shell,scripting,Linux,Bash,Shell,Scripting,基本上我有一个文件,为了理解如何写这个,看起来像这样 Start: First line of text Second line of text Bin: Third line of text Four line of text 我需要完成的是编写一个脚本来检查这些字符串并输出任何缺少的字符串 基于我的假设,我假设这将涉及一个awk或grep,它将检查每个字符串是否存在,以及一组if语句,如果不存在,则输出字符串不存在的内容 有关于如

基本上我有一个文件,为了理解如何写这个,看起来像这样

Start:
       First line of text
       Second line of text
Bin:
       Third line of text
       Four  line of text 
我需要完成的是编写一个脚本来检查这些字符串并输出任何缺少的字符串

基于我的假设,我假设这将涉及一个awk或grep,它将检查每个字符串是否存在,以及一组if语句,如果不存在,则输出字符串不存在的内容

有关于如何开始的建议吗? 这是我到目前为止用的一个小伪代码。 `


类似这样的内容应使用AWK打印缺少的字符串:

BEGIN {
 a[i++]="Start:"
 a[i++]="First line of text"
 a[i++]="Second line of text"
}

// {
 for (s in a) {
  if (match($0,a[s]) ) { a[s]="" }
 }
}

END {
 for (s in a) {
  if (a[s] != "") { print a[s] }
 }
}

你能给我们看看你想要的产量吗?到目前为止,您尝试过什么?什么构成“缺少字符串”?您知道
diff
cmd吗?它应该为您提供一种标准化的方法来查找文件中的差异。可能不完全是您所设想的格式,但它是linux/unix环境中常见的std工具。祝你好运。缺少的字符串意味着当我检查一个预先确定的字符串,比如上面变量中的字符串,它不在文件中时,我需要输出它不在那里。
BEGIN {
 a[i++]="Start:"
 a[i++]="First line of text"
 a[i++]="Second line of text"
}

// {
 for (s in a) {
  if (match($0,a[s]) ) { a[s]="" }
 }
}

END {
 for (s in a) {
  if (a[s] != "") { print a[s] }
 }
}