find-splitpara.sh

来自「Shall高级编程」· Shell 代码 · 共 65 行

SH
65
字号
#!/bin/bash# find-splitpara.sh#  Finds split paragraphs in a text file,#+ and tags the line numbers.ARGCOUNT=1       # Expect one arg.E_WRONGARGS=65file="$1"        # Target filename.lineno=1         # Line number. Start at 1.Flag=0           # Blank line flag.if [ $# -ne "$ARGCOUNT" ]then  echo "Usage: `basename $0` FILENAME"  exit $E_WRONGARGSfi  file_read ()     # Scan file for pattern, then print line.{while read linedo  if [[ "$line" =~ ^[a-z] && $Flag -eq 1 ]]     then  # Line begins with lc character, following blank line.     echo -n "$lineno::   "     echo "$line"  fi  if [[ "$line" =~ "^$" ]]     then     #  If blank line,     Flag=1   #+ set flag.  else     Flag=0  fi  ((lineno++))done} < $file  # Redirect file into function's stdin.file_readexit $?# ----------------------------------------------------------------This is line one of an example paragraph, bla, bla, bla.This is line two, and line three should follow on next line, butthere is a blank line separating the two parts of the paragraph.# ----------------------------------------------------------------Running this script on a file containing the above paragraphyields:4::   there is a blank line separating the two parts of the paragraph.There will be additional output for all the other split paragraphsin the target file.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?