#!/bin/bash
#наити все записи в секции ifdFriendlyName и удалить их и соответствующие им записи в секциях ifdVendorId and ifdProductId

plist=$2
searchString=$1
while :
do
	searchResults=($( grep -n "${searchString}" ${plist} | sed -e 's/:.*//g' ))
	numOfFoundEntries=$(echo ${searchResults[@]} | wc -w)
	#echo "SearchString $searchString"
	#echo  ${numOfFoundEntries}
	if [ ${numOfFoundEntries} -eq 0 ] ; then
		exit 0
	fi
	
	friendlyName=$( grep -n "<key>ifdFriendlyName</key>" ${plist} | sed -e 's/:.*//g')
	relativePos=$(( ${searchResults[0]}-${friendlyName} ))
	sed -i -e "$(( ${friendlyName}+${relativePos} ))d" $plist
	
	productID=$( grep -n "<key>ifdProductID</key>" ${plist} | sed -e 's/:.*//g')
	sed -i -e "$(( ${productID}+${relativePos} ))d" $plist
	
	vendorID=$( grep -n "<key>ifdVendorID</key>" ${plist} | sed -e 's/:.*//g')
	sed -i -e "$(( ${vendorID}+${relativePos}))d" $plist	
done