Script help

Technical issues/questions of an intermediate or advanced nature.
User avatar
Ed_P
Contributor
Contributor
Posts: 8341
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Script help

Post#1 by Ed_P » 25 Apr 2017, 06:30

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
Ed

Evan
Shogun
Shogun
Posts: 466
Joined: 11 Apr 2016, 09:00
Distribution: Distribution: *

Re: Script help

Post#2 by Evan » 25 Apr 2017, 07:17

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.

Bogomips
Full of knowledge
Full of knowledge
Posts: 2564
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

Re: Script help

Post#3 by Bogomips » 25 Apr 2017, 12:51

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'
    
Linux porteus 4.4.0-porteus #3 SMP PREEMPT Sat Jan 23 07:01:55 UTC 2016 i686 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux
NVIDIA Corporation C61 [GeForce 6150SE nForce 430] (rev a2) MemTotal: 901760 kB MemFree: 66752 kB

User avatar
normalGuy
Black ninja
Black ninja
Posts: 52
Joined: 06 Nov 2015, 23:36
Distribution: porteus 3.2 xfce archBang
Location: uk & portugal

Re: Script help

Post#4 by normalGuy » 25 Apr 2017, 21:09

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

User avatar
Ed_P
Contributor
Contributor
Posts: 8341
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Re: Script help

Post#5 by Ed_P » 26 Apr 2017, 03:23

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:
Ed

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Re: Script help

Post#6 by Rava » 17 Dec 2018, 20:09

Nice code snippets indeed. Ed_P, thanks for the heads up.
Cheers!
Yours Rava

Post Reply