Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 21 Oct 2014, 10:04
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Get results on different lines
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 1 Posts_count  
Author Message
ASRI éducation


Joined: 09 May 2009
Posts: 2531
Location: France

PostPosted: Wed 15 Oct 2014, 23:54    Post_subject:  Get results on different lines
Sub_title: Script to list content of folders on reposit
 

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

Current script:
Code:
#!/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:
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:
spacefm_0.9.4-0_20141009.pet



What I want to get
File /tmp/pou/autoupdate_lazypuppy_tmp2 => packages listed on different lines
Code:
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:
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 => Association | Forum | Dépôt | Espace kids
Back to top
View user's profile Send_private_message Visit_website 
CatDude


Joined: 03 Jan 2007
Posts: 1484
Location: UK

PostPosted: Thu 16 Oct 2014, 03:33    Post_subject:  

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/files/asriedu_packages/asriedu_packages_30x_base_puppylucid52x/
resulted in 383 files (on separate lines) in both autoupdate_lazypuppy_tmp1 and autoupdate_lazypuppy_tmp2

Code:
#!/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
.

_________________

Back to top
View user's profile Send_private_message 
dejan555


Joined: 30 Nov 2008
Posts: 2681
Location: Montenegro

PostPosted: Thu 16 Oct 2014, 11:56    Post_subject:  

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

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


after:

Code:
TempFolder="/tmp/pou"

_________________


Back to top
View user's profile Send_private_message Visit_website MSNM 
ASRI éducation


Joined: 09 May 2009
Posts: 2531
Location: France

PostPosted: Thu 16 Oct 2014, 16:55    Post_subject:  

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.
Very Happy

_________________
Projet ASRI éducation => Association | Forum | Dépôt | Espace kids
Back to top
View user's profile Send_private_message Visit_website 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0605s ][ Queries: 11 (0.0066s) ][ GZIP on ]