header image

An update to the bash script that takes a parameter:

August 31st, 2010 § 0 comments

#!/bin/bash

book=$1

[[ -z $book ]] && { echo “No argument supplied, exiting!”; exit 1; }

[[ ! -e $book ]] && { echo “Can’t find a file with the name $book, exiting”; exit 1; }

title=${book%.*}
bookcounter=0
linecounter=0
sed -i ‘s/r$//’ “$book”
while read line
do
((linecounter+=1))
if [[ $linecounter -gt 300 && -z "$line" || -z "$output_file" ]]; then
linecounter=0
((bookcounter+=1))
formatted_bookcounter=$(printf “%03d” $bookcounter)
output_file=”${title}${formatted_bookcounter}.txt”
echo “…starting segment $output_file”
echo “$title – segment $formatted_bookcounter” > $output_file
echo “===================” >> $output_file
echo “” >> $output_file
fi
echo “$line” >> $output_file
done < “$book”

Tagged ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

What's this?

You are currently reading An update to the bash script that takes a parameter: at The Cowgirl Coder.

meta