0

I have following string

11-22-33-44-55-66-77-88-99-1010-1111-1212

I want to extract 88-99-1010-111 from that string

  • 1
    You really want 111 or 1111 ? – pLumo Oct 15 '19 at 12:36
1

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 -.
2

Use cut:

Based on delimiter and fields:

echo 11-22-33-44-55-66-77-88-99-1010-1111-1212 | cut -d- -f 8-11

Based on character position:

echo 11-22-33-44-55-66-77-88-99-1010-1111-1212 | cut -c 22-36

Or use bash parameter substition:

var=11-22-33-44-55-66-77-88-99-1010-1111-1212
echo ${var:21:15}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.