Skip to main content
added 15 characters in body
Source Link
Cyrus
  • 5.6k
  • 1
  • 23
  • 30

Try this with bash builtin commands:

#!/bin/bash

l=1                          # paragraph counter
echo -n $l                   # print paragraph counter without new line
while read x; do             # read current line from file, see last line
  if [[ $x == "" ]]; then    # empty line?
    echo                     # print empty line
    read x                   # read next line from file, see last line
    ((l++))                  # increment paragraph counter
    echo -n $l               # print paragraph counter without new line
  fi
  echo "$x"                  # print current line
done < file

Try this with bash builtin commands:

#!/bin/bash

l=1                          # paragraph counter
echo -n $l                   # print paragraph counter without new line
while read x; do             # read current line from file
  if [[ $x == "" ]]; then    # empty line?
    echo                     # print empty line
    read x                   # read next line from file
    ((l++))                  # increment paragraph counter
    echo -n $l               # print paragraph counter without new line
  fi
  echo "$x"                  # print current line
done < file

Try this with bash builtin commands:

#!/bin/bash

l=1                          # paragraph counter
echo -n $l                   # print paragraph counter without new line
while read x; do             # read current line from file, see last line
  if [[ $x == "" ]]; then    # empty line?
    echo                     # print empty line
    read x                   # read next line from file, see last line
    ((l++))                  # increment paragraph counter
    echo -n $l               # print paragraph counter without new line
  fi
  echo "$x"                  # print current line
done < file
deleted 73 characters in body
Source Link
Cyrus
  • 5.6k
  • 1
  • 23
  • 30

Try this with bash builtin commands:

#!/bin/bash

l=1                          # paragraph counter
echo -n $l                   # print paragraph counter without new line
while read x; do             # read current line from file
  if [[ $x == "" ]]; then    # empty line?
    echo                     # print empty line
    read x                   # read next line from file
    ((l++))                  # increment paragraph counter
    echo "$l$x"-n $l               # print paragraph counter andwithout currentnew line
    continue                 # continue while loop
  fi
  echo "$x"                  # print current line
done < file

Try this with bash builtin commands:

#!/bin/bash

l=1                          # paragraph counter
echo -n $l                   # print paragraph counter
while read x; do             # read line from file
  if [[ $x == "" ]]; then    # empty line?
    echo                     # print empty line
    read x                   # read next line from file
    ((l++))                  # increment paragraph counter
    echo "$l$x"              # print paragraph counter and current line
    continue                 # continue while loop
  fi
  echo "$x"                  # print current line
done < file

Try this with bash builtin commands:

#!/bin/bash

l=1                          # paragraph counter
echo -n $l                   # print paragraph counter without new line
while read x; do             # read current line from file
  if [[ $x == "" ]]; then    # empty line?
    echo                     # print empty line
    read x                   # read next line from file
    ((l++))                  # increment paragraph counter
    echo -n $l               # print paragraph counter without new line
  fi
  echo "$x"                  # print current line
done < file
Source Link
Cyrus
  • 5.6k
  • 1
  • 23
  • 30

Try this with bash builtin commands:

#!/bin/bash

l=1                          # paragraph counter
echo -n $l                   # print paragraph counter
while read x; do             # read line from file
  if [[ $x == "" ]]; then    # empty line?
    echo                     # print empty line
    read x                   # read next line from file
    ((l++))                  # increment paragraph counter
    echo "$l$x"              # print paragraph counter and current line
    continue                 # continue while loop
  fi
  echo "$x"                  # print current line
done < file