Skip to content

Commit

Permalink
0.20180804
Browse files Browse the repository at this point in the history
fb2totxt: select all body
  • Loading branch information
zvezdochiot committed Aug 4, 2018
1 parent 2cd3d6f commit 6a6e9ae
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Console FB2 reader
https://github.com/zvezdochiot/bash-fb2

0.20180804

fb2totxt: select all body

0.20180803

fb2tozip: auto/force mode
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.20180725
0.20180804
3 changes: 2 additions & 1 deletion man/man1/fb2encode.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "FB2totxt User Manual" 0.20180803 "3 Aug 2018" "User documentation"
.TH "FB2totxt User Manual" 0.20180804 "4 Aug 2018" "User documentation"

.SH NAME
fb2encode
Expand Down Expand Up @@ -29,6 +29,7 @@ help
All rights reserved.

.SH SEE ALSO
fb2toinfo,
fb2totxt,
fb2tozip,
fb2tofix,
Expand Down
43 changes: 43 additions & 0 deletions man/man1/fb2toinfo.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.TH "FB2totxt User Manual" 0.20180804 "04 Aug 2018" "User documentation"

.SH NAME
fb2toinfo

.SH DESCRIPTION
Bash-script for console FB2 info reader

.SH SYNOPSIS
fb2totxt [options] book.fb2

.SH OPTIONS
.TP
-o name.txt
name text file (default = stdout)
.TP
-z
force unzip (default = false)
.TP
-h
help

.SH EXAMPLE
fb2toinfo book.fb2.zip

.SH COPYRIGHT
Copyright 2018 zvezdochiot.
All rights reserved.

.SH SEE ALSO
fb2encode,
fb2totxt,
fb2tozip,
fb2xmlfix,
sed,
file,
less,
unzip,
zcat

.SH CONTACTS
Website: https://github.com/zvezdochiot/bash-fb2
Email: [email protected]
3 changes: 2 additions & 1 deletion man/man1/fb2totxt.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "FB2totxt User Manual" 0.20180803 "03 Aug 2018" "User documentation"
.TH "FB2totxt User Manual" 0.20180804 "04 Aug 2018" "User documentation"

.SH NAME
fb2totxt
Expand Down Expand Up @@ -32,6 +32,7 @@ help

.SH SEE ALSO
fb2encode,
fb2toinfo,
fb2tozip,
fb2xmlfix,
sed,
Expand Down
3 changes: 2 additions & 1 deletion man/man1/fb2tozip.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "FB2totxt User Manual" 0.20180803 "3 Aug 2018" "User documentation"
.TH "FB2totxt User Manual" 0.20180804 "4 Aug 2018" "User documentation"

.SH NAME
fb2tozip
Expand Down Expand Up @@ -33,6 +33,7 @@ help

.SH SEE ALSO
fb2encode,
fb2toinfo,
fb2totxt,
fb2xmlfix,
unzip,
Expand Down
3 changes: 2 additions & 1 deletion man/man1/fb2xmlfix.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "FB2totxt User Manual" 0.20180803 "03 Aug 2018" "User documentation"
.TH "FB2totxt User Manual" 0.20180804 "04 Aug 2018" "User documentation"

.SH NAME
fb2xmlfix
Expand Down Expand Up @@ -30,6 +30,7 @@ help

.SH SEE ALSO
fb2encode,
fb2toinfo,
fb2totxt,
fb2tozip,
xmlstarlet
Expand Down
2 changes: 1 addition & 1 deletion scripts/fb2encode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#Depends: dash, grep, sed, iconv

sname="Fb2Encode"
sversion="0.20180803"
sversion="0.20180804"

echo "$sname $sversion" >&2

Expand Down
90 changes: 90 additions & 0 deletions scripts/fb2toinfo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/sh

#fb2toinfo.sh
#Depends: dash, sed, file, unzip, zcat

sname="Fb2toinfo"
sversion="0.20180804"

echo "$sname $sversion" >&2

tnocomp=""
tcomp="sed"
[ ! "$(command -v $tcomp)" ] && tnocomp="$tnocomp $tcomp"
tcomp="file"
[ ! "$(command -v $tcomp)" ] && tnocomp="$tnocomp $tcomp"
tcomp="unzip"
[ ! "$(command -v $tcomp)" ] && tnocomp="$tnocomp $tcomp"
tcomp="zcat"
[ ! "$(command -v $tcomp)" ] && tnocomp="$tnocomp $tcomp"
if [ "+$tnocomp" != "+" ]
then
echo "Not found:${tnocomp}!" >&2
echo "" >&2
exit 1
fi

fzip="false"
fhlp="false"
while getopts ":o:zh" opt
do
case $opt in
o) dst="$OPTARG"
;;
h) fhlp="true"
;;
z) fzip="true"
;;
*) echo "Unknown option -$OPTARG"
exit 1
;;
esac
done
shift "$(($OPTIND - 1))"
src="$1";

if [ "x$src" = "x" -o "x$fhlp" = "xtrue" ]
then
echo "Usage:"
echo "$0 [options] book.fb2"
echo "Options:"
echo " -o name.txt name text file (default = stdout)"
echo " -z force unzip (default = false)"
echo " -h help"
exit 0
fi

if [ ! -f "$src" ]
then
echo "Not found $src!" >&2
exit 1
fi

if [ "x$src" = "x$dst" ]
then
dst="$dst.txt"
fi

sedcmdf='s/<body>/\n&\n/;s/<\/body>/\n&\n/;'
sedcmds='/<body/,$d;'
sedcmdu='s/<[^>]+>//g;/^[[:space:]]*$/d'
fcompr=$(file -b -i "$src")
[ "x$fzip" = "xtrue" ] && fcompr="application/zip; charset=binary"
[ "x$fgzip" = "xtrue" ] && fcompr="application/gzip; charset=binary"

if [ "x$fcompr" = "xapplication/zip; charset=binary" ]
then
if [ -z "$dst" ]
then
unzip -c "$src" | sed -e "$sedcmdf" | sed -e "$sedcmds" | sed -r "$sedcmdu"
else
unzip -c "$src" | sed -e "$sedcmdf" | sed -e "$sedcmds" | sed -r "$sedcmdu" > "$dst"
fi
else
if [ -z "$dst" ]
then
zcat "$src" | sed -e "$sedcmdf" | sed -e "$sedcmds" | sed -r "$sedcmdu"
else
zcat "$src" | sed -e "$sedcmdf" | sed -e "$sedcmds" | sed -r "$sedcmdu" > "$dst"
fi
fi
18 changes: 9 additions & 9 deletions scripts/fb2totxt.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/sh

#fb2totext.sh
#fb2totxt.sh
#Depends: dash, sed, file, less, unzip, zcat

sname="Fb2totxt"
sversion="0.20180803"
sversion="0.20180804"

echo "$sname $sversion" >&2

Expand Down Expand Up @@ -72,7 +72,7 @@ then
fi

sedcmdf='s/<body>/\n&\n/;s/<\/body>/\n&\n/;'
sedcmds='1,/<body>/d;/<\/body>/,$d;'
sedcmds='/<body/,/<\/body>/p;'
sedcmdu='s/<[^>]+>//g;/^[[:space:]]*$/d'
fcompr=$(file -b -i "$src")
[ "x$fzip" = "xtrue" ] && fcompr="application/zip; charset=binary"
Expand All @@ -82,25 +82,25 @@ if [ "x$fcompr" = "xapplication/zip; charset=binary" ]
then
if [ "x$fless" = "xtrue" ]
then
unzip -c "$src" | sed -e "$sedcmdf" | sed -e "$sedcmds" | sed -r "$sedcmdu" | less
unzip -c "$src" | sed -e "$sedcmdf" | sed -n -e "$sedcmds" | sed -r "$sedcmdu" | less
else
if [ -z "$dst" ]
then
unzip -c "$src" | sed -e "$sedcmdf" | sed -e "$sedcmds" | sed -r "$sedcmdu"
unzip -c "$src" | sed -e "$sedcmdf" | sed -n -e "$sedcmds" | sed -r "$sedcmdu"
else
unzip -c "$src" | sed -e "$sedcmdf" | sed -e "$sedcmds" | sed -r "$sedcmdu" > "$dst"
unzip -c "$src" | sed -e "$sedcmdf" | sed -n -e "$sedcmds" | sed -r "$sedcmdu" > "$dst"
fi
fi
else
if [ "x$fless" = "xtrue" ]
then
zcat "$src" | sed -e "$sedcmdf" | sed -e "$sedcmds" | sed -r "$sedcmdu" | less
zcat "$src" | sed -e "$sedcmdf" | sed -n -e "$sedcmds" | sed -r "$sedcmdu" | less
else
if [ -z "$dst" ]
then
zcat "$src" | sed -e "$sedcmdf" | sed -e "$sedcmds" | sed -r "$sedcmdu"
zcat "$src" | sed -e "$sedcmdf" | sed -n -e "$sedcmds" | sed -r "$sedcmdu"
else
zcat -c "$src" | sed -e "$sedcmdf" | sed -e "$sedcmds" | sed -r "$sedcmdu" > "$dst"
zcat "$src" | sed -e "$sedcmdf" | sed -n -e "$sedcmds" | sed -r "$sedcmdu" > "$dst"
fi
fi
fi
2 changes: 1 addition & 1 deletion scripts/fb2tozip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#Depends: dash, zip, unzip

sname="Fb2toZip"
sversion="0.20180803"
sversion="0.20180804"

echo "$sname $sversion" >&2

Expand Down
2 changes: 1 addition & 1 deletion scripts/fb2xmlfix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#Depends: dash, xmlstarlet

sname="Fb2XMLFix"
sversion="0.20180803"
sversion="0.20180804"

echo "$sname $sversion" >&2

Expand Down

0 comments on commit 6a6e9ae

Please sign in to comment.