Guest User

Untitled

a guest
Jan 27th, 2023
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.36 KB | Source Code | 0 0
  1. #!/bin/bash
  2. #problem: grep gives "memory exhausted" error on 6TB disks
  3. ##solution: read it on parts
  4. if [ -z $2 ] || ! [ -e $1 ]; then echo "$0 file string|less -S # greps in chunks"; exit; fi
  5.  
  6. FILE="$1"
  7. MATCH="$2"
  8.  
  9. nlines=$(wc -l < $1)
  10. chunk=1000
  11. LC_ALL=C
  12. for((i=1; i < nlines; i += chunk))
  13. do
  14.   sed -n $i,+$((chunk - 1))p $1 | grep -F -a -z -C 500 $2
  15. done
Advertisement
Add Comment
Please, Sign In to add comment