show dots when script is "thinking"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting show dots when script is "thinking"
# 1  
Old 05-07-2010
show dots when script is "thinking"

Hey, I'm running the following script:

Code:
#!/bin/bash

kjv=kjv.txt
trim(){
    local trim_string
    local _TRIM=$1
    trim_string=${_TRIM##*[${2:- }]}
    _TRIM=${_TRIM#"trim_string"}
    echo $_TRIM
}

#trim() {
#    echo $( _trim "$@" )
#}

printf "How many chapters? "
read response

while IFS=: read book chapter verse text
do
    #this is a temp variable!
    chapterCount=$response
    chapterNumber=$( trim "$chapter" 0 )
    if [ $chapterNumber -le $chapterCount ]
    then 
        firstword=${text%% *}
        printf "%s %s:%s %s\n" "$book" "$chapter" "$verse" "$firstword"
    fi
done < "$kjv"
printf "\n"

Basically it takes the first word out of each verse of a specified amount of chapters from a text file. Since the file is so large it takes some time and sometimes looks like its stuck. How can I add dots (periods) or something of that nature every time it's "thinking"?
# 2  
Old 05-07-2010
Code:
line_count=0
blocksize=1000
while IFS=: read book chapter verse text
do
    line_count=`expr $line_count+1`
    if [ $line_count -gt $blocksize ]
      then 
         echo ".\c"
         line_count=0
     fi
    #this is a temp variable!
    chapterCount=$response
    chapterNumber=$( trim "$chapter" 0 )
    if [ $chapterNumber -le $chapterCount ]
    then 
        firstword=${text%% *}
        printf "%s %s:%s %s\n" "$book" "$chapter" "$verse" "$firstword"
    fi
done < "$kjv"

Some systems need "echo -e"
Adjust blocksize to suit.
You may have to adjust the output of the printf to go to a file, depending on how the script is called

Last edited by jgt; 05-07-2010 at 03:44 PM.. Reason: Wrote some of it in wrong language
# 3  
Old 05-07-2010
I'm thinking, I'm thinking...I'm...thinking:

Code:
#!/bin/ksh
# busy - show progress indicators
# Heiner Steven (heiner.steven@odn.de)
#
#  usage:
#     busy& busipid=$!
#     # do some actions
#     kill $busypid
#  set -x 

#  Give some eye candy... 
set -A Indicators -- "\n  |o.............................|  " \
                     "\n  |0o............................|  " \
                     "\n  |)0o...........................|  " \
                     "\n  |()0o..........................|  " \
                     "\n  |0()0o.........................|  " \
                     "\n  |o0()0o........................|  " \
                     "\n  |.o0()0o.......................|  " \
                     "\n  |..o0()0o......................|  " \
                     "\n  |...o0()0o.....................|  " \
                     "\n  |....o0()0o....................|  " \
                     "\n  |.....o0()0o...................|  " \
                     "\n  |......o0()0o..................|  " \
                     "\n  |.......o0()0o.................|  " \
                     "\n  |........o0()0o................|  " \
                     "\n  |.........o0()0o...............|  " \
                     "\n  |..........o0()0o..............|  " \
                     "\n  |...........o0()0o.............|  " \
                     "\n  |............o0()0o............|  " \
                     "\n  |.............o0()0o...........|  " \
                     "\n  |..............o0()0o..........|  " \
                     "\n  |...............o0()0o.........|  " \
                     "\n  |................o0()0o........|  " \
                     "\n  |.................o0()0o.......|  " \
                     "\n  |..................o0()0o......|  " \
                     "\n  |...................o0()0o.....|  " \
                     "\n  |....................o0()0o....|  " \
                     "\n  |.....................o0()0o...|  " \
                     "\n  |......................o0()0o..|  " \
                     "\n  |.......................o0()0o.|  " \
                     "\n  |........................o0()0o|  " \
                     "\n  |.........................o0()0|  " \
                     "\n  |..........................o0()|  " \
                     "\n  |...........................o0(|  " \
                     "\n  |............................o0|  " \
                     "\n  |.............................o|  " \
                     "\n  |............................o0|  " \
                     "\n  |...........................o0(|  " \
                     "\n  |..........................o0()|  " \
                     "\n  |.........................o0()0|  " \
                     "\n  |........................o0()0o|  " \
                     "\n  |.......................o0()0o.|  " \
                     "\n  |......................o0()0o..|  " \
                     "\n  |.....................o0()0o...|  " \
                     "\n  |....................o0()0o....|  " \
                     "\n  |...................o0()0o.....|  " \
                     "\n  |..................o0()0o......|  " \
                     "\n  |.................o0()0o.......|  " \
                     "\n  |................o0()0o........|  " \
                     "\n  |...............o0()0o.........|  " \
                     "\n  |..............o0()0o..........|  " \
                     "\n  |.............o0()0o...........|  " \
                     "\n  |............o0()0o............|  " \
                     "\n  |...........o0()0o.............|  " \
                     "\n  |..........o0()0o..............|  " \
                     "\n  |.........o0()0o...............|  " \
                     "\n  |........o0()0o................|  " \
                     "\n  |.......o0()0o.................|  " \
                     "\n  |......o0()0o..................|  " \
                     "\n  |.....o0()0o...................|  " \
                     "\n  |....o0()0o....................|  " \
                     "\n  |...o0()0o.....................|  " \
                     "\n  |..o0()0o......................|  " \
                     "\n  |.o0()0o.......................|  " \
                     "\n  |o0()0o........................|  " \
                     "\n  |0()0o.........................|  " \
                     "\n  |()0o..........................|  " \
                     "\n  |)0o...........................|  " \
                     "\n  |0o............................|  " \


#  Make an array of the aforementioned eye candy... 
integer n=${#Indicators[@]}
integer i=0

#  While condition exists, present status to screen... 
while [[ -f bpc.txt ]] 2>/dev/null #true
do
   clear 
#   print -n -- "Running ... \n\t${Indicators[i]}\n"
   print "Running ... \n\t${Indicators[i]}\r"
   ((i=(i+1)%n))
#  sleep 1
#  clear
done

Note that you'd want to modify the condition that drives the while... loop.

Last edited by curleb; 05-07-2010 at 04:24 PM.. Reason: reduce flicker per print args...
# 4  
Old 05-07-2010
What are all those block-characters in the print statement?

Instead of clearing the screen every time, try printing a carriage return instead of a newline. It will overwrite the last busy line with the next one.
# 5  
Old 05-07-2010
hey, you're right...
# 6  
Old 05-07-2010
Quote:
Originally Posted by jgt
Code:
line_count=0
blocksize=1000
while IFS=: read book chapter verse text
do
    line_count=`expr $line_count+1`
    if [ $line_count -gt $blocksize ]
      then 
         echo ".\c"
         line_count=0
     fi
    #this is a temp variable!
    chapterCount=$response
    chapterNumber=$( trim "$chapter" 0 )
    if [ $chapterNumber -le $chapterCount ]
    then 
        firstword=${text%% *}
        printf "%s %s:%s %s\n" "$book" "$chapter" "$verse" "$firstword"
    fi
done < "$kjv"

Some systems need "echo -e"
Adjust blocksize to suit.
You may have to adjust the output of the printf to go to a file, depending on how the script is called
So now I have:
Code:
#!/bin/bash

kjv=kjv.txt
trim(){
    local trim_string
    local _TRIM=$1
    trim_string=${_TRIM##*[${2:- }]}
    _TRIM=${_TRIM#"trim_string"}
    echo $_TRIM
}

#trim() {
#    echo $( _trim "$@" )
#}

printf "How many chapters? "
read response

line_count=0
blocksize=1000
while IFS=: read book chapter verse text
do
    line_count=`expr $line_count+1`
    if [ $line_count -gt $blocksize ]
      then 
         echo ".\c"
         line_count=0
     fi
    #this is a temp variable!
    chapterCount=$response
    chapterNumber=$( trim "$chapter" 0 )
    if [ $chapterNumber -le $chapterCount ]
    then 
        firstword=${text%% *}
        printf "%s %s:%s %s\n" "$book" "$chapter" "$verse" "$firstword"
    fi
done < "$kjv"

and i get the following error:

integer expression expected
/home/administrator/bin/pk8-1: line 24: [: 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+ 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+ 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+ 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+ 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+ 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+ 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+ 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+ 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+ 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1

which is the line:
Code:
if [ $line_count -gt $blocksize ]

# 7  
Old 05-07-2010
spaces are important.
Code:
line_count=`expr $line_count + 1`

Sorry, my heart was in the right place, but my syntax wasn't

Last edited by jgt; 05-07-2010 at 07:43 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Can someone please show me a very simple "expect" script to change password in Solaris please?

Ladies & Gents, Can one of you gurus please show me a very simple "expect" script to change the password in Solaris in a script, please? Nothing fancy, no error checking, no nothing. Just to change the password of a new user, it's all. Many thanks in advance. U guys have honestly earned my... (1 Reply)
Discussion started by: Hiroshi
1 Replies

3. Red Hat

"/usr/sbin/hpacucli ctrl all show" command does not work

Dear Concern, We have observed that following command stuck/does not work in some RedHat nodes. Please advise us to troubleshoot the issue. /usr/sbin/hpacucli ctrl all show Note: HP Array Configuration Utility CLI for Linux 64-bit With Best Regards, Md. Abdullah-Al Kauser (3 Replies)
Discussion started by: makauser
3 Replies

4. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

5. Shell Programming and Scripting

Awk-sed - wc : how to count DOTS "."'s in a file.

Hi Experts , file: EST 2013::.................................................................................................................................................................................................................................................cmihx021:/home/data1/ ... (11 Replies)
Discussion started by: rveri
11 Replies

6. Shell Programming and Scripting

perl - Removing dots(".") from the data

Hi Friends, I have a file1 as below file1.txt 100000.||1925-01-10|00:00|1862SHERMA NAVE#1SE.||EVTON|IL|60201||22509.|BDSS|62007|2639.|26670 100001.||1935-01-10|00:00|1862NEW . YRK NO.||EVTON|IL|60201||22509.|BDSS|62007|2639.|26670. 100002.||1965-01-10|00:00|1862 IND . INC,CL... (6 Replies)
Discussion started by: i150371485
6 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question