Get results on different lines

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
ASRI éducation
Posts: 3197
Joined: Sat 09 May 2009, 12:10
Location: France
Contact:

Get results on different lines

#1 Post by ASRI éducation »

Hello
I worked for several days on a script (POU), but I'm stuck on a detail.
I need your help!

Current script:

Code: Select all

#!/bin/sh -v
#Script to list content of folders on reposit ASRI (Sourceforge)
#20141015

URLPACKAGES="http://sourceforge.net/projects/asriedu/files/asriedu_packages/asriedu_packages_dev/spacefm/"
TempFolder="/tmp/pou"

AVPET=` curl -s -L $URLPACKAGES | awk 'BEGIN{ RS="<a href=" ; FS="\"" } {print $2 }' | grep '\.pet/download$' | sort -f -u | tr '\n' ' ' `

echo $AVPET > $TempFolder/autoupdate_lazypuppy_tmp2
sed -i 's/\/download//g' $TempFolder/autoupdate_lazypuppy_tmp2
rm $TempFolder/autoupdate_lazypuppy_tmp1

cat $TempFolder/autoupdate_lazypuppy_tmp2 |
while read ONELINE
do
ShortName="$(basename "$ONELINE")"
echo "$ShortName" >> $TempFolder/autoupdate_lazypuppy_tmp1
done

exit

Current results:
File /tmp/pou/autoupdate_lazypuppy_tmp2 => This is where I have a problem.
I want the packages listed on different lines. Currently, all gathered in one line.

Code: Select all

http://sourceforge.net/projects/asriedu/files/asriedu_packages/asriedu_packages_dev/spacefm/spacefm_0.9.4-0_20141009_DOC.pet http://sourceforge.net/projects/asriedu/files/asriedu_packages/asriedu_packages_dev/spacefm/spacefm_0.9.4-0_20141009_NLS.pet http://sourceforge.net/projects/asriedu/files/asriedu_packages/asriedu_packages_dev/spacefm/spacefm_0.9.4-0_20141009.pet
File /tmp/pou/autoupdate_lazypuppy_tmp1 => One package is referenced, yet three are on the server.

Code: Select all

spacefm_0.9.4-0_20141009.pet

What I want to get
File /tmp/pou/autoupdate_lazypuppy_tmp2 => packages listed on different lines

Code: Select all

http://sourceforge.net/projects/asriedu/files/asriedu_packages/asriedu_packages_dev/spacefm/spacefm_0.9.4-0_20141009_DOC.pet
http://sourceforge.net/projects/asriedu/files/asriedu_packages/asriedu_packages_dev/spacefm/spacefm_0.9.4-0_20141009_NLS.pet
http://sourceforge.net/projects/asriedu/files/asriedu_packages/asriedu_packages_dev/spacefm/spacefm_0.9.4-0_20141009.pet
File /tmp/pou/autoupdate_lazypuppy_tmp1 => Three packages referenced

Code: Select all

spacefm_0.9.4-0_20141009_DOC.pet
spacefm_0.9.4-0_20141009_NLS.pet
spacefm_0.9.4-0_20141009.pet
Thank you in advance.
Regards
Projet ASRI éducation => [url=http://asri-education.org/]Association[/url] | [url=http://forum.asri-education.org/]Forum[/url] | [url=http://dl01.asri-education.org/]Dépôt[/url] | [url=http://kids.asri-education.org/]Espace kids[/url]

User avatar
CatDude
Posts: 1563
Joined: Wed 03 Jan 2007, 17:49
Location: UK

#2 Post by CatDude »

Hello ASRI

I made edits to two lines in your original code and it is now working OK here.

Testing it with the URLPACKAGES changed to: http://sourceforge.net/projects/asriedu ... ylucid52x/
resulted in 383 files (on separate lines) in both autoupdate_lazypuppy_tmp1 and autoupdate_lazypuppy_tmp2

Code: Select all

#!/bin/sh -v
#Script to list content of folders on reposit ASRI (Sourceforge)
#20141015

URLPACKAGES="http://sourceforge.net/projects/asriedu/files/asriedu_packages/asriedu_packages_dev/spacefm/"
TempFolder="/tmp/pou"

#AVPET=` curl -s -L $URLPACKAGES | awk 'BEGIN{ RS="<a href=" ; FS="\"" } {print $2 }' | grep '\.pet/download$' | sort -f -u | tr '\n' ' ' `
AVPET=` curl -s -L $URLPACKAGES | awk 'BEGIN{ RS="<a href=" ; FS="\"" } {print $2 }' | grep '\.pet/download$' `

#echo $AVPET > $TempFolder/autoupdate_lazypuppy_tmp2 
echo $AVPET | tr " " "\n" | sort -f -u > $TempFolder/autoupdate_lazypuppy_tmp2
sed -i 's/\/download//g' $TempFolder/autoupdate_lazypuppy_tmp2
rm $TempFolder/autoupdate_lazypuppy_tmp1

cat $TempFolder/autoupdate_lazypuppy_tmp2 |
while read ONELINE
do
ShortName="$(basename "$ONELINE")"
echo "$ShortName" >> $TempFolder/autoupdate_lazypuppy_tmp1
done

exit
CatDude
.
[img]http://www.smokey01.com/CatDude/.temp/sigs/acer-futile.gif[/img]

User avatar
dejan555
Posts: 2798
Joined: Sun 30 Nov 2008, 11:57
Location: Montenegro
Contact:

#3 Post by dejan555 »

Tested CatDude's script, it worked after I created the temp dir, so I suggest adding this line too:

Code: Select all

[ ! -d $TempFolder ] && mkdir -p $TempFolder
after:

Code: Select all

TempFolder="/tmp/pou"
puppy.b0x.me stuff mirrored [url=https://drive.google.com/open?id=0B_Mb589v0iCXNnhSZWRwd3R2UWs]HERE[/url] or [url=http://archive.org/details/Puppy_Linux_puppy.b0x.me_mirror]HERE[/url]

User avatar
ASRI éducation
Posts: 3197
Joined: Sat 09 May 2009, 12:10
Location: France
Contact:

#4 Post by ASRI éducation »

Hello CatDude and dejan555.
A huge big thank you for your answers and your responsiveness.
It had been three long evenings this problem prevented me from continuing to improve the POU utility.
Now, everything works!
:wink:

Note: In addition to POU, I will be able to use this code to create a utility for download files (pet / sfs) present on the storage servers I use.
:D
Projet ASRI éducation => [url=http://asri-education.org/]Association[/url] | [url=http://forum.asri-education.org/]Forum[/url] | [url=http://dl01.asri-education.org/]Dépôt[/url] | [url=http://kids.asri-education.org/]Espace kids[/url]

Post Reply