Skip to main content
2 of 3
deleted 3 characters in body
Rakesh Sharma
  • 859
  • 1
  • 5
  • 7

Store lines in separate containers depending on whether they need to move south or remain in place. Then when all lines have been looked at this way, print them in the desired order.

$ perl -ne 'push @{/_00[2468]$/ ? \@A : \@B}, $_}{print @B, @A' input.txt

You can do this with posix sed also:

$ sed -ne '
    /_00[2468]$/ s//&/w data2468
   //!p
    $r data2468
' input.txt
Rakesh Sharma
  • 859
  • 1
  • 5
  • 7