Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.02 KB | None | 0 0
  1. #!/bin/bash
  2. SAVEDIFS=$IFS
  3. IFS=$(echo -en "\n\b")
  4. for elem in `find . -mindepth 1 -maxdepth 1  -type f`
  5. do
  6.   if  head -n 1 $elem | grep -q '^data:'
  7.   then
  8.     is_valid=true
  9.     line_list=$(cat $elem | cut -d$'\n' -f2-)
  10.     for line in $line_list
  11.     do
  12.       linecut=$(echo $line | cut -d "#" -f 1)
  13.       if [[ ! -z "${linecut// }" ]]
  14.       then
  15.         if [[ ! $linecut =~ ^[on]:[0-9]{3}:[a-z]+:[0-9]+:[0-9]+$ ]]
  16.         then
  17.           is_valid=false
  18.         fi
  19.       fi
  20.     done
  21.     if [ "$is_valid" = true ]
  22.     then
  23.       echo $elem: | cut -d / -f 2 | tr [A-Z] [a-z]
  24.       head -n 1 $elem
  25.       for line in $line_list
  26.       do
  27.         linecut=$(echo $line | cut -d "#" -f 1)
  28.         if [[ ! -z "${linecut// }" ]]
  29.         then
  30.           echo $linecut
  31.           if [[ $linecut == o* ]]
  32.           then
  33.             echo $linecut >> o_lines
  34.           fi
  35.           if [[ $linecut == n* ]]
  36.           then
  37.             echo $linecut >> n_lines
  38.           fi
  39.         fi
  40.       done
  41.     fi
  42.   fi
  43. done
  44. IFS=$SAVEDIFS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement