I have following string
11-22-33-44-55-66-77-88-99-1010-1111-1212I want to extract 88-99-1010-111 from that string
12 Answers
Use cut:
Based on delimiter and fields:
echo 11-22-33-44-55-66-77-88-99-1010-1111-1212 | cut -d- -f 8-11Based on character position:
echo 11-22-33-44-55-66-77-88-99-1010-1111-1212 | cut -c 22-36Or use bash parameter substition:
var=11-22-33-44-55-66-77-88-99-1010-1111-1212
echo ${var:21:15} With awk:
echo 11-22-33-44-55-66-77-88-99-1010-1111-1212 | awk 'BEGIN {FS=OFS="-"} {print $8,$9,$10,$11}'BEGIN {FS=OFS="-"}is used to set both the field separator (FS) and the output field separator (OFS) to-.