I have a text file with a line of text that cantains numbers and text formatted ito groups. I need to extract the number that can be either 1,2 or 3 digits long. and write it to a variable, but i need to remove any leading spaces in the number first.
I can get the numbers out but how to remove the leading spaces?
My test file contents
Code:
"C 56","Home athletics center","LAC"
And my Script that will pull out the 3 digint number after the first C
Code:
#!/bin/bash
#set initial variables
file="FILE.EXT" # input filename
while read line
do centnum=${line:2:3} # find 3 Chars in line
centnam=$(echo $line | cut -d '"' -f4) #Extract the Center Name from the file
done <"$file"
echo D';'$centnum';'$centnam';;M;;' > MM_file.txt
the number in the output file needs to be just the significant digits and is a CSV so can be variable length.
I have tried using sed, but this just parses the entire file at once and I cannot process each line individually.
TIA
Ken