LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-14-2021, 01:01 PM   #31
igadoter
Senior Member
 
Registered: Sep 2006
Location: wroclaw, poland
Distribution: many, primary Slackware
Posts: 2,717
Blog Entries: 1

Rep: Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625

Of course you right. Just to illustrate possible list use. And having lists is convenient. But one more thing. Script should use separate working directory. Due to fact that if it will fail during execution - rerun would give incorrect numbers. Say after performing conversion of pdf file - script exits. Now rerun will count twice the same file. Working directory partially fix this. If script exit code is non-zero all working directory is cleared up - files are copied again and script runs again.

Edit: This is version with if condition. I don't understand reason for branching - if there are text files count - if there are not converse and count words. Seems something is not right here. But
Code:
wc -w *.txt > word_count 2> /dev/null || {
  for i in *.odcx ; do odc2txt "$i" ; done
  for i in *.odt ; do odt2txt "$i" ; done
  for i in *.pdf ; do pdf2txt "$i" ; done
  wc -w *.txt > word_count 2> /dev/null ;}
and that's it

Last edited by igadoter; 07-14-2021 at 01:21 PM.
 
1 members found this post helpful.
Old 07-15-2021, 01:35 AM   #32
salmanahmed
Member
 
Registered: Jun 2020
Posts: 158

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by dugan View Post
This is one of the newer BASH books. It has a good reputation.

https://linuxcommand.org/tlcl.php
Thanks a lot. I will definitely look into it
 
Old 07-15-2021, 01:42 AM   #33
salmanahmed
Member
 
Registered: Jun 2020
Posts: 158

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by igadoter View Post
Ok what about
Code:
DOCX=(*.docx)
ODT=(*.odt)
PDF=(*.pdf)

# correct conversion command format so they produce files with .txt suffix
for i in ${DOCX[@]} ; do docx2txt "$i" ; done 
for i in ${ODT[@]} ; do  odt2txt "$i$ ; done
for i in ${PDF[@]} ; do pdf2txt  "$i"; done

# the last
wc *.txt > total_word_count
Say
Code:
$ wc -w *.info > /tmp/total_word_info
$ cat /tmp/total_word_info 
  11 Jinja2.info
  11 MarkupSafe.info
  21 Sphinx.info
  11 alabaster.info
  11 imagesize.info
  11 mando.info
  15 python3-babel.info
  11 pytz.info
  11 snowballstemmer.info
  11 sphinxcontrib-applehelp.info
  11 sphinxcontrib-devhelp.info
  11 sphinxcontrib-htmlhelp.info
  11 sphinxcontrib-jsmath.info
  11 sphinxcontrib-qthelp.info
  11 sphinxcontrib-serializinghtml.info
 179 total
So you really don't want to go back? At least run what I posted.
Yes, it works. I made minor modification in the syntax of pdf2txt and odt2txt (as mentioned in their manpages):
Code:
#!/bin/bash
DOCX=(*.docx)
ODT=(*.odt)
PDF=(*.pdf)

# correct conversion command format so they produce files with .txt suffix
for i in ${DOCX[@]} ; do docx2txt "$i"; done
for i in ${ODT[@]} ; do  odt2txt "$i" --output="$i".txt ; done
for i in ${PDF[@]} ; do pdf2txt -o "$i".txt "$i" ; done

# the last
wc -w *.txt > total_word_count
After looking at your code, I realized my initial mistake, i.e instead of appending the wordcount_file (and use if and loop for it), why not just convert all files and generate new wordcount_file, as the wordcount for existing text files remain the same
 
Old 07-15-2021, 05:00 AM   #34
igadoter
Senior Member
 
Registered: Sep 2006
Location: wroclaw, poland
Distribution: many, primary Slackware
Posts: 2,717
Blog Entries: 1

Rep: Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625
I am happy I could be of some help.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] [bash] `test -n $VAR` : Too many arguments Michael Uplawski Programming 2 04-17-2018 12:45 AM
[SOLVED] Bash Script too Many Arguments error knowlgain Linux - Newbie 2 05-30-2016 08:36 PM
[SOLVED] Bash curdir throwing "too many arguments" tc60045 Programming 4 04-08-2013 12:30 PM
logname: no login name, -bash: [: too many arguments da_kidd_er Linux - General 1 10-27-2004 02:09 PM
BASH says "too many arguments" in terminal tmitch70377 Linux - Newbie 4 12-06-2003 05:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration