Advertisement
Guest User

AWK SO2 PWr

a guest
May 20th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.63 KB | None | 0 0
  1. #! /usr/bin/bash
  2.  
  3. # Check the number of arhuments
  4. if [ "$#" -ne 1 ]; then
  5.     echo "Error! Wrong number of parameters!"
  6.     exit 1
  7. fi
  8.  
  9. # Check if first and second parameters are direcotories
  10. if [ ! -f $1 ]; then
  11.     echo "Error! Parameter must be directory!"
  12.     exit 1
  13. fi
  14.  
  15. # Script contents
  16. gawk 'BEGIN {line_num=1; files_found=0}\
  17.     {sub( /\/\/.*$/, "", $0 )}
  18.     /#include[ ]*((<.*>)|(\".*\"))/ {includes[files_found]=$0;\
  19.         includes[files_found]=gensub( /.*([<"])(.*)([>"]).*/, "\\2", 1, includes[files_found] );\
  20.         files_found+=1};\
  21.     NF != 0 {print line_num ". " $0; line_num+=1};\
  22.     END {for ( key in includes ) print includes[key]}'\
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement