Technical issues/questions of an intermediate or advanced nature.
-
Ed_P
- Contributor
- Posts: 8360
- Joined: 06 Feb 2013, 22:12
- Distribution: Cinnamon 5.01 ISO
- Location: Western NY, USA
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
Ed_P
-
Bogomips
- Full of knowledge
- Posts: 2564
- Joined: 25 Jun 2014, 15:21
- Distribution: 3.2.2 Cinnamon & KDE5
- Location: London
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
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
Bogomips
-
normalGuy
- Black ninja
- Posts: 52
- Joined: 06 Nov 2015, 23:36
- Distribution: porteus 3.2 xfce archBang
- Location: uk & portugal
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:
or
normalGuy
-
Ed_P
- Contributor
- Posts: 8360
- Joined: 06 Feb 2013, 22:12
- Distribution: Cinnamon 5.01 ISO
- Location: Western NY, USA
Post#5
by Ed_P » 26 Apr 2017, 03:23
Wow!!
Bogomips wrote:[*]For Your Eyes Only
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:
Thank you guys.
I do
love this forum.
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%.
Ed
Ed_P
-
Rava
- Contributor
- Posts: 5401
- Joined: 11 Jan 2011, 02:46
- Distribution: XFCE 5.01 x86_64 + 4.0 i586
- Location: Forests of Germany
Post#6
by Rava » 17 Dec 2018, 20:09
Nice code snippets indeed. Ed_P, thanks for the heads up.
Cheers!
Yours Rava
Rava