我有一個文件有不同的文本行,我想檢查是否是相同模式的重複。查找字符串中的模式linux
在文件:
Blah
Blah
Depends: ssloader, firmware (>= 3.0), firmware (<= 6.0), apta
blah
我的目標是讓 「> = 3.0」 & 「< = 6.0」 到文件中。但請記住,有時只有1個「固件」依賴性。
我有什麼到目前爲止,只有抓住了第一次固件信息:
if grep -Fq "firmware (" inputfile #checks if pattern exists
then
compat=$(look 'Depends:' inputfile) #grab line where pattern is
compat=${##*firmware (} #remove pattern and other stuff infront
compat=${compat%%)*} #remove other stuff behind ")"
echo $compat >> outputfile
fi
我想知道如何檢查,如果有在同一行超過1種模式。或者如果有超過1行的模式相同,如何識別該行可以獲得固件值。由於
編輯:
我最初的目的是檢測是否有相同圖案的不止一個。我對想法持開放態度。 :)
是這樣的:
if (more than one of same pattern)
get both values #I am open to ideas to get this done <---
else
get value of this pattern
fi
EDIT2:
我做它像這樣得到這個工作;
if grep -Fq "firmware (" ./control
then
compat=$(look 'Depends:' control)
compat=${compat#*firmware (}
compat=${compat%%)*}
echo -n $compat > ./compatibility.txt
if [ $(grep -o "firmware (" ./control | wc -l) -eq 2 ]; then
compat=$(look 'Depends:' control)
compat=${compat##*firmware (}
compat=${compat%%)*}
echo " $compat" >> ./compatibility.txt
fi
fi
我知道這絕對是非常外行,而且它只能如果模式是在「依賴」的標籤。
任何想法/輸入?
是它始終將是'firmware',或者是你在尋找任何重複'取決於:',或任何標記行中的任何重複? – geekosaur 2012-04-27 03:43:58
另外,可能會有多少重複? – geekosaur 2012-04-27 03:51:30
它有時會成爲'firmware',其他標籤如'Pre-depends:'可能有'firmware'信息。 – AlwynIsPat 2012-04-27 03:52:27