-4

For example

1cn1
1cn2
1cn3
1cn4
1cn5
1cn6
1cn7
1cn8
1cn9
1cn10
1cn11
1cn12

extract lines between 1cn8 to 1cn12

like this i have hundreds of line, want to extract any range by giving the input.

$ cat test | grep '[$0-9]'
1cn1
1cn2
1cn3
1cn4
1cn5
1cn6
1cn7
1cn8
1cn9
1cn10
1cn11
1cn12

these are node names, want to extract node names within the node range. lines starting from1cn8 till 1cn12

nu11p01n73R
  • 26,397
  • 3
  • 39
  • 52

1 Answers1

0

You can try something like that:

[[:alnum:]]{3}([8-9]|1[0-2])

Short explanation:

  • [[:alnum:]]{3}: matchs with any letter (upper or lower case) and digits, over 3 times;
  • ([8-9]|1[0-2]): matchs with 8 and 9 [8-9] OR |, the number one with 0, 1 or 2, 1[0-2]
$ cat test
1cn1
1cn2
1cn3
1cn4
1cn5
1cn6
1cn7
1cn8
1cn9
1cn10
1cn11
1cn12
$ egrep '[[:alnum:]]{3}([8-9]|1[0-2])' test
1cn8
1cn9
1cn10
1cn11
1cn12