Ubuntu – Extract a number in a txt file by using regular expressions

bashcommand linepythontext processing

I am saving the output of terminal by 2>&1 | tee ./
results.txt
in a .txt file which has the following text:

executing: ./home/images/image-001-041.png
0,33, /results/image-001-041.png
1.7828,32, /results/image-001-040.png
1.86051,34, /results/image-001-042.png
1.90462,31, /results/image-001-039.png
1.90954,30, /results/image-001-038.png
1.91953,35, /results/image-001-043.png
1.92677,28, /results/image-001-036.png
1.92723,3160, /results/image-037-035.png
1.93353,7450, /results/image-086-035.png
1.93375,1600, /results/image-019-044.png

I need to take the second numbers (after first comma sign, i.e. 33,32,34,…) and save it in a list in Python. What is the bash command, or the regular expression command in python?
Thanks

Best Answer

Using cut:

cut -sd',' -f2 < result.txt

from man cut:

-d, --delimiter=DELIM
          use DELIM instead of TAB for field delimiter
-s, --only-delimited
          do not print lines not containing delimiters
-f, --fields=LIST
          select only these fields;  also print any line that contains
          no delimiter character, unless the -s option is specified