Page 1 of 1

Script help

Posted: 25 Apr 2017, 06:30
by Ed_P
How do I access lines in a text file one at a time?

I'm trying to have a script that displays the current Firefox ESR version number. And at this point I have:

Code: Select all

#!/bin/sh

FIREFOX=https://download-installer.cdn.mozilla.net/pub/firefox/releases/
ARCH=i386
if [ `echo $MACHTYPE | sed -e 's/-.*$//'` = x86_64 ]; then
   ARCH=x86_64
fi

if [ -d  "/tmp/ffreleases" ]; then
   rm /tmp/ffreleases/index*
   rm /tmp/rels5s
fi

#set -x
wget $FIREFOX                                     -P /tmp/ffreleases > /dev/null 2>&1
cat /tmp/ffreleases/index.html | grep "releases/5" > /tmp/rels5s
cat /tmp/rels5s                | grep "esr/"       > /tmp/esrs

cat /tmp/esrs
which displays a list of 4 or 5 ESR entries. The only entry I am interested in is the last one and the things I've tried only display the 1st one.

Code: Select all

ESRS=$(cat /tmp/esrs)
echo $ESRS
read td href <<< $ESRS
echo $href

Re: Script help

Posted: 25 Apr 2017, 07:17
by Evan
https://ftp.mozilla.org/pub/firefox/rel ... README.txt

Don't know if the instructions for getting the latest-esr with wget is any help for your script.

Re: Script help

Posted: 25 Apr 2017, 12:51
by Bogomips
Lazy way. :)
  • Text File

    Code: Select all

    guest@porteus:~$ cat $g/Qns.txt
    interesting - please post the output of 'lspci -knn' command
    
    a) for java please download following packages through USM:
    - openjre
    - icedtea-web
    - cups
    
    b) for VLC plugin for Firefox:
    - vlc
    - npapi-vlc
    
    sgnfile=some_name.sgn
    
       ... This cheatcode specifies the *.sgn file which Porteus will
           search for.  This is useful when you want to store several
           Porteus editions on one disk/disc.
           Example: 'sgnfile=porteus-usb.sgn
  • For Your Eyes Only :wink:

    Code: Select all

    guest@porteus:~$ readarray -t q < $g/Qns.txt
    guest@porteus:~$ echo $q
    interesting - please post the output of 'lspci -knn' command
    guest@porteus:~$ echo ${q[${#q[*]}-1]}
    Example: 'sgnfile=porteus-usb.sgn'
     
  • Explanation

    Code: Select all

    guest@porteus:~$ echo ${#q[*]}   # Array Size
    17
    guest@porteus:~$ echo ${q[16]}  # Last Element of Array. where q is an Array
    Example: 'sgnfile=porteus-usb.sgn'
    

Re: Script help

Posted: 25 Apr 2017, 21:09
by normalGuy
hi,

Maybe it's not this but if you want just to grab the last line - in this case the last version number:

Code: Select all

...
cat /tmp/esrs | tail -n 1
or

Code: Select all

...
cat /tmp/rels5s | tail -n 1

Re: Script help

Posted: 26 Apr 2017, 03:23
by Ed_P
Wow!!
Bogomips wrote:[*]For Your Eyes Only :wink:

Code: Select all

guest@porteus:~$ readarray -t q < $g/Qns.txt
guest@porteus:~$ echo $q
interesting - please post the output of 'lspci -knn' command
guest@porteus:~$ echo ${q[${#q[*]}-1]}
Example: 'sgnfile=porteus-usb.sgn'
 
normalGuy wrote: Maybe it's not this but if you want just to grab the last line - in this case the last version number:

Code: Select all

...
cat /tmp/esrs | tail -n 1
Thank you guys. :beer: I do love this forum. :friends:

My final results (at this point).

Code: Select all

#cat /tmp/esrs

echo
readarray -t ESRS < /tmp/esrs
read td href <<< ${ESRS[${#ESRS[*]}-1]}
echo ${href:27:-19}
#cat /tmp/esrs | tail -n 1

if [ "$1" != "" ]; then cat /tmp/esrs; fi
read 
exit
BTW Distinguishing between ({[gq]}) characters with my eyes can be difficult but I finally got them at 170%. :lol:

Re: Script help

Posted: 17 Dec 2018, 20:09
by Rava
Nice code snippets indeed. Ed_P, thanks for the heads up.