From 6a6e9aee46ab177686836e297cea67e9fa46c046 Mon Sep 17 00:00:00 2001 From: zvezdochiot Date: Sat, 4 Aug 2018 10:59:28 +0300 Subject: [PATCH] 0.20180804 fb2totxt: select all body --- CHANGELOG | 4 ++ VERSION | 2 +- man/man1/fb2encode.1 | 3 +- man/man1/fb2toinfo.1 | 43 +++++++++++++++++++++ man/man1/fb2totxt.1 | 3 +- man/man1/fb2tozip.1 | 3 +- man/man1/fb2xmlfix.1 | 3 +- scripts/fb2encode.sh | 2 +- scripts/fb2toinfo.sh | 90 ++++++++++++++++++++++++++++++++++++++++++++ scripts/fb2totxt.sh | 18 ++++----- scripts/fb2tozip.sh | 2 +- scripts/fb2xmlfix.sh | 2 +- 12 files changed, 158 insertions(+), 17 deletions(-) create mode 100644 man/man1/fb2toinfo.1 create mode 100755 scripts/fb2toinfo.sh diff --git a/CHANGELOG b/CHANGELOG index 1022d79..f39eda5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 diff --git a/VERSION b/VERSION index bc85b61..ad575f1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.20180725 +0.20180804 diff --git a/man/man1/fb2encode.1 b/man/man1/fb2encode.1 index 614fa75..6e3c61b 100644 --- a/man/man1/fb2encode.1 +++ b/man/man1/fb2encode.1 @@ -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 @@ -29,6 +29,7 @@ help All rights reserved. .SH SEE ALSO + fb2toinfo, fb2totxt, fb2tozip, fb2tofix, diff --git a/man/man1/fb2toinfo.1 b/man/man1/fb2toinfo.1 new file mode 100644 index 0000000..13a0e75 --- /dev/null +++ b/man/man1/fb2toinfo.1 @@ -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: zvezdochiot@users.sourceforge.net diff --git a/man/man1/fb2totxt.1 b/man/man1/fb2totxt.1 index 3bb7b5a..9dc8fc7 100644 --- a/man/man1/fb2totxt.1 +++ b/man/man1/fb2totxt.1 @@ -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 @@ -32,6 +32,7 @@ help .SH SEE ALSO fb2encode, + fb2toinfo, fb2tozip, fb2xmlfix, sed, diff --git a/man/man1/fb2tozip.1 b/man/man1/fb2tozip.1 index bdf85cf..57840fa 100644 --- a/man/man1/fb2tozip.1 +++ b/man/man1/fb2tozip.1 @@ -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 @@ -33,6 +33,7 @@ help .SH SEE ALSO fb2encode, + fb2toinfo, fb2totxt, fb2xmlfix, unzip, diff --git a/man/man1/fb2xmlfix.1 b/man/man1/fb2xmlfix.1 index 67e4a0f..812bcfe 100644 --- a/man/man1/fb2xmlfix.1 +++ b/man/man1/fb2xmlfix.1 @@ -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 @@ -30,6 +30,7 @@ help .SH SEE ALSO fb2encode, + fb2toinfo, fb2totxt, fb2tozip, xmlstarlet diff --git a/scripts/fb2encode.sh b/scripts/fb2encode.sh index cadc423..95576a8 100755 --- a/scripts/fb2encode.sh +++ b/scripts/fb2encode.sh @@ -4,7 +4,7 @@ #Depends: dash, grep, sed, iconv sname="Fb2Encode" -sversion="0.20180803" +sversion="0.20180804" echo "$sname $sversion" >&2 diff --git a/scripts/fb2toinfo.sh b/scripts/fb2toinfo.sh new file mode 100755 index 0000000..0ca0b29 --- /dev/null +++ b/scripts/fb2toinfo.sh @@ -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//\n&\n/;s/<\/body>/\n&\n/;' +sedcmds='/ "$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 diff --git a/scripts/fb2totxt.sh b/scripts/fb2totxt.sh index c6e9aff..55a9cd0 100755 --- a/scripts/fb2totxt.sh +++ b/scripts/fb2totxt.sh @@ -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 @@ -72,7 +72,7 @@ then fi sedcmdf='s//\n&\n/;s/<\/body>/\n&\n/;' -sedcmds='1,//d;/<\/body>/,$d;' +sedcmds='//p;' sedcmdu='s/<[^>]+>//g;/^[[:space:]]*$/d' fcompr=$(file -b -i "$src") [ "x$fzip" = "xtrue" ] && fcompr="application/zip; charset=binary" @@ -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 diff --git a/scripts/fb2tozip.sh b/scripts/fb2tozip.sh index 9df21a8..01f653e 100755 --- a/scripts/fb2tozip.sh +++ b/scripts/fb2tozip.sh @@ -4,7 +4,7 @@ #Depends: dash, zip, unzip sname="Fb2toZip" -sversion="0.20180803" +sversion="0.20180804" echo "$sname $sversion" >&2 diff --git a/scripts/fb2xmlfix.sh b/scripts/fb2xmlfix.sh index 2a88942..340aaea 100755 --- a/scripts/fb2xmlfix.sh +++ b/scripts/fb2xmlfix.sh @@ -4,7 +4,7 @@ #Depends: dash, xmlstarlet sname="Fb2XMLFix" -sversion="0.20180803" +sversion="0.20180804" echo "$sname $sversion" >&2