I have a file which would contain something like:
CUSTOMER_MSISDNS
447999999999
The list of MSISDNs can carry on and be unlimited, and there is no set position where this section may be in the file due to expanding top elements, so to find the line number I use:
MSISDN_LINE=$(cat -n ${FILE} | grep 'CUSTOMER_MSISDNS' | awk '{print $1}')
This will return say 29 the line of CUSTOMER_MSISDNS in my ${FILE}
element. I then use a while
loop to read all lines after that number by:
LINE=1
while read line
do
if [ $LINE -le $MSISDN_LINE ]
then
LINE=$(($LINE+1))
continue
fi
done
However I keep finding that it will always leave the last line off the file out. Ending the line in this example on line 29 excluding line 30 with the actual MSISDN on.
To solve this I added a character return into the file which then allowed the MSISDN on line 30 to be selected, however I cannot guarantee that there will be a character return when I am not testing. Any Ideas on how I can solve this.
cat ${FILE} | wc -l would also not show the last line of the file