Advertisement
p0ssum

print_data

Feb 29th, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. COUNT=0
  4.  
  5. #Create two arrays, one for the start, one for the end
  6. START=($(grep -n Orange test.txt | awk -F: '{print $1}' | sed -e :a -e '$!N; s/\n/ /; ta' ))
  7. END=($(grep -n "\-\-\-\-$" test.txt | awk -F: '{print $1}' | sed -e :a -e '$!N; s/\n/ /; ta' ))
  8.  
  9. # Find the last index of the array(subtract 1)
  10. let ARRAY_END=${#START[*]}-1
  11.  
  12. while [ $COUNT -le $ARRAY_END ]
  13. do
  14.  
  15. # get start of print
  16. let ACTUAL=${START[$COUNT]}-2
  17. let STOP=${END[$COUNT]}+0
  18. sed -n "$ACTUAL,${STOP}p" test.txt
  19. let COUNT=$COUNT+1
  20.  
  21. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement