With perl, because array slices are convenient and so is the ability to treat each pair of elements in an array as the key & value of a hash:
$ perl -F/ -lane '%f = @F[1..$#F]; print $f{F}' input.txt 2 5 9 7 8 3 6 8 3 6
Perl's -F and -a (autosplit) work similarly to awk - but instead of auto-splitting the line into $1, $2, $3, etc, it auto-splits each line into an array called @F.
The script converts a slice of array @F (all but the zeroth element) into a hash (associative array) called %f, and prints the element of %f with key 'F'.
To highlight what this does/how it works (and why we needed to exclude the empty string zeroth element of @F), here's what @F and %f look like when using the Data::Dump module's dump function:
$ perl -F/ -MData::Dump=dump -lane ' %f = @F[1..$#F]; print join("\n", $_, dump(@F), dump(\%f), $f{F}), "\n"' input.txt /A/1/B/1/C/1/D/1/E/1/F/2/G/1/H/1/I/1/J/1/K/1/ ("", "A", 1, "B", 1, "C", 1, "D", 1, "E", 1, "F", 2, "G", 1, "H", 1, "I", 1, "J", 1, "K", 1) { A => 1, B => 1, C => 1, D => 1, E => 1, F => 2, G => 1, H => 1, I => 1, J => 1, K => 1 } 2 /B/1/C/1/D/1/E/1/F/5/G/1/H/1/I/1/J/1/K/1/ ("", "B", 1, "C", 1, "D", 1, "E", 1, "F", 5, "G", 1, "H", 1, "I", 1, "J", 1, "K", 1) { B => 1, C => 1, D => 1, E => 1, F => 5, G => 1, H => 1, I => 1, J => 1, K => 1 } 5 /C/1/D/1/E/1/F/9/G/1/H/1/I/1/J/1/K/1/ ("", "C", 1, "D", 1, "E", 1, "F", 9, "G", 1, "H", 1, "I", 1, "J", 1, "K", 1) { C => 1, D => 1, E => 1, F => 9, G => 1, H => 1, I => 1, J => 1, K => 1 } 9 ...and so on...
Note: this will print a blank line if there is no F in the input. If that's not what you want, do something like:
perl -F/ -lane '%f = @F[1..$#F]; if (defined $f{F}) { print $f{F} } else { print STDERR "Error on input line $.: F has absconded" }' input.txt
awk -F'/' '/F/ { for (i=1;i<=NF;i++) if ($i ~ "F") print $(i+1) }' infilewhereinfileis your input filesed -nr -e 's^.*F([0-9]+).*^\1^p'I love sed, but you may not need it (if that is all you are doing. Hard to tell. )