AWK/sed – write a text in a text file before number which is lower than specific value

With your shown samples, could you please try following.

awk '
/^\[/{ next }
{
  for(i=1;i<=NF;i++){
    if($i>=1 && $i<=58050){
      tempfirstGroup=(tempfirstGroup?tempfirstGroup OFS:"")$i
    }
    if($i>=58051 && $i<=116100){
      tempsecondGroup=(tempsecondGroup?tempsecondGroup OFS:"")$i
    }
  }
  if(tempfirstGroup){
      firstGroup=(firstGroup?firstGroup ORS:"")tempfirstGroup
  }
  if(tempsecondGroup){
      secondGroup=(secondGroup?secondGroup ORS:"") tempsecondGroup
  }
  tempsecondGroup=tempfirstGroup=""
}
END{
  print "[  Index 1  ]" ORS firstGroup ORS "[  Index 2  ]" ORS secondGroup
}
' Input_file

Output will be as follows.

[  Index 1  ]
1628 5704
32801
[  Index 2  ]
61605
71508 90612
102606

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top