I have a file that has different lines of texts, I would like to check if the are duplicates of the same pattern.
In the file:
Blah
Blah
Depends: ssloader, firmware (>= 3.0), firmware (<= 6.0), apta
blah
my aim is to get ">= 3.0" & "<= 6.0" into a file. but bear in mind that sometimes there's only 1 "firmware" dependency.
What i have so far, only grabs the 1st firmware info:
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
I would like to know how to check if there's more than 1 pattern in the same line. Or if there's more than 1 line with the same pattern, how to identify that line can get the firmware value. Thanks
EDIT:
My initial intention is to detect if there are more than one of the same pattern. I am open to ideas. :)
something like this:
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:
I've got this working by doing it like this;
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
I know it's definitely very layman, and it works only if the pattern is in the "Depends:" label.
Any ideas/inputs?
firmware, or are you looking for any duplication in aDepends:, or any duplication in any labeled line?firmwareas at times, other labels likePre-depends:might have thefirmwareinfo.