kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/cxx/extractor/testdata/skip_functions.sh (about) 1 # Output every line except ones that contains match_string. Also, do not output 2 # extra_lines_to_skip lines that follow the line that contained match_string. 3 function skip() { 4 if [ $# -ne 3 ] && [ $# -ne 2 ]; then 5 echo "Usage: $0 match_string extra_lines_to_skip [input_file]" 6 return 1 7 fi 8 local -r match_string="$1" 9 local -r lines_to_skip="$2" 10 11 if [ $# -eq 2 ]; then 12 awk "/$match_string/{skip=$lines_to_skip;next} skip>0{--skip;next} {print}" 13 else 14 awk "/$match_string/{skip=$lines_to_skip;next} skip>0{--skip;next} {print}" "$3" 15 fi 16 return 0 17 } 18 19 # Modify input_file to remove lines that contains match_string. Also remove 20 # extra_lines_to_skip lines that follow the line that contained match_string. 21 function skip_inplace() { 22 if [ $# -ne 3 ]; then 23 echo "Usage: $0 match_string lines_to_skip input_file" 24 return 1 25 fi 26 local -r match_string="$1" 27 local -r lines_to_skip="$2" 28 local -r input_file="$3" 29 30 local -r temp_file=$(mktemp) 31 skip "$match_string" "$lines_to_skip" "$input_file" > "$temp_file" 32 mv "$temp_file" "$input_file" 33 }