Skip to content

Instantly share code, notes, and snippets.

@eungjun-yi
Last active April 13, 2017 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eungjun-yi/d223181fa6e43b0c372137fa34d317e6 to your computer and use it in GitHub Desktop.
Save eungjun-yi/d223181fa6e43b0c372137fa34d317e6 to your computer and use it in GitHub Desktop.
Correct numbers of list
#!/bin/bash
number=1
while read line
do
echo $line | grep -E '^[0-9][0-9]*' > /dev/null
if [ "$?" = "0" ]; then
echo $line | sed "s/^[0-9][0-9]*\./$number\./"
number=`echo $number+1|bc`
else
echo $line
fi
done
@eungjun-yi
Copy link
Author

example:

echo '1. foo                                                                                                                                                                          17:55:10
quote> 
quote> 3. bar
quote> 
quote> 4. baz' | ~/bin/numbering.sh 
1. foo

2. bar

3. baz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment