0

I have some files(.txt), the name are:

run_freq100ampl0.6offs0.8_1
run_freq100ampl0.4offs1.1_1
run_freq100ampl0.2offs1.0_1
run_freq100ampl0.4offs1.2_1
run_freq100ampl0.2offs1.1_1
run_freq100ampl0.5offs0.8_1
run_freq100ampl0.2offs1.2_1
run_freq100ampl0.4offs0.8_1

I want get the number of ampl, like

0.6
0.4
0.2
0.4
0.2
0.5
0.2
0.4

How can i do it with 'find', 'grep' or 'cat' in Linux?

Matteo
  • 14,696
  • 9
  • 68
  • 106

3 Answers3

1

Using grep:

grep -Po '(?<=ampl).*(?=offs)' input

Example:

$ grep -Po '(?<=ampl).*(?=offs)' <<< "run_freq100ampl0.2offs1.1_1"
0.2

Using sed:

$ sed 's/.*ampl\(.*\)offs.*/\1/' <<< "run_freq100ampl0.2offs1.1_1"
0.2
devnull
  • 118,548
  • 33
  • 236
  • 227
0

Using awk

awk -F"ampl|off" '{print $2}'
0.6
0.4
0.2
0.4
0.2
0.5
0.2
0.4

Or using fixed position

awk '{print substr($0,16,3)}'
Jotne
  • 40,548
  • 12
  • 51
  • 55
0
for f in *.txt
do
  f=${f%offs*}
  f=${f#*ampl}
  echo ${f}
done
twalberg
  • 59,951
  • 11
  • 89
  • 84