output text in between

how can i output the number 2641569270623 from a text file called checkpoint.txt that is a one line file (generated by a maths sieving program) that looks like:
pmin=2641569270623,factor_count=8,cpu_secs=1705.793,frac_done=0.002592,elapsed_secs=1710.844

i tried sed -n "/pmin=/,/,factor/ p" checkpoint.txt | sed "$ d" which ouputs nothing and sed -n "/pmin=/,/,factor/ p" checkpoint.txt which output the whole line

Try this:

sed '/^pmin=/s/pmin=\([^,]*\),.*/\1/' file

Regards

Ranges in sed are ranges of entire lines -- /pmin=/,/,factor/ means print each line starting with a line containing "pmin=" through a different line containing ",factor" (and starting over again if a subsequent line matches "pmin=" again).

You could do

sed -e 's/.*pmin=//;s/,factor.*//' checkpoint.txt

which will replace from start of line through "pmin=" with empty line, and ditto from ",factor" through to end of line. The result is still printed regardless of whether the resulting line is empty or not.

both arguments work PERFECTLY. thanks alot guys!

is it possible to use this output to replace text from another file in one command?

ie: replace the "720" in line 1 of a different file with text comtaining "Sieved to 720" with the 2641569270623 we extracted from the original file?

sed -e 's/.*pmin=/s%Sieved to [0-9]*%Sieved to /;s/,factor.*/%/' checkpoint.txt |
sed -f - otherfile

If your sed won't do "-f -" you will have to save to a temporary file.

The repetition of "Sieved to " can be avoided, but is left as an exercise.

You can also include the whole sed command within the sed command and pipe it to sh:

sed '/^pmin=/s/pmin=\([^,]*\),.*/sed '"'"'s%Sieved to [0-9]*%Sieved to \1%'"'"' other_file/' file | sh

until you are more familiar with regular expressions, you can use field based operations

awk -F"," '{ split($1,a,"="); print a[2] }' file
awk -F'[=,]' '{print $2}' file
sed 's#^[^=][^=]*=\([^,][^,]*\).*#\1#' file