input: http://pastebin.com/raw.php?i=MqPXZwc3
output: http://pastebin.com/raw.php?i=8QCkp4yv
it will be a long day.. :D
could someone please help with it?
i have to make a "one liner" that get's the input, and gives the mentioned output.
On 3 July 2010 10:07, Jozsi Avadkan jozsi.avadkan@gmail.com wrote:
input: http://pastebin.com/raw.php?i=MqPXZwc3
output: http://pastebin.com/raw.php?i=8QCkp4yv
it will be a long day.. :D
could someone please help with it?
i have to make a "one liner" that get's the input, and gives the mentioned output.
Can I ask "why" you need to do this before I provide the answer, which took me about 5 minutes to write in bash script.
I only ask because this seems to me like some kind of elementary homework assignment on bash scripting and I don't want to be involved in doing someone's homework for them.
it will be a site, were i put my notes
2010. 07. 3, szombat keltezéssel 10.58-kor Sam Sharpe ezt írta:
On 3 July 2010 10:07, Jozsi Avadkan jozsi.avadkan@gmail.com wrote:
input: http://pastebin.com/raw.php?i=MqPXZwc3
output: http://pastebin.com/raw.php?i=8QCkp4yv
it will be a long day.. :D
could someone please help with it?
i have to make a "one liner" that get's the input, and gives the mentioned output.
Can I ask "why" you need to do this before I provide the answer, which took me about 5 minutes to write in bash script.
I only ask because this seems to me like some kind of elementary homework assignment on bash scripting and I don't want to be involved in doing someone's homework for them.
-- Sam
On 3 July 2010 11:09, Jozsi Avadkan jozsi.avadkan@gmail.com wrote:
it will be a site, were i put my notes
I'll give you the benefit of the doubt based on the fact a quick Google search says you ask questions a lot and they don't all look like homework ;o)
If you have the filenames in a file, you can do this:
cat list.txt | ( function title { echo "<br><font size=4>$1</font><br>" ; } ; function ending { echo "<br>" ; }; function link { LINK=$1 ; LINKFILE=${LINK##*/} ; LINKNAME=${LINKFILE%.html} ; echo "<a href="$LINK">$LINKNAME</a> |" ; } ; PREVTITLE="" ; TITLE="" ; while read line; do TITLE="${line%%/*}" ; if [ "$TITLE" != "$PREVTITLE" ]; then if [ "$PREVTITLE" != "x" ]; then ending "" ; fi ; title $TITLE ; PREVTITLE=$TITLE ; fi ; link $line ; done ; )
If you have a tree of links, you could replace "cat list.txt" with "find ./ -type f"
The pretty version looks like this:
################################################## #!/bin/bash
function title { echo "<br><font size=4>$1</font><br>" }
function ending { echo "<br>" }
function link { # prints out the link template given the path to link to LINK=$1 # delete the longest match of */ from the left side of the path, to give the filename (equivalent to running `basename $LINK`) LINKFILE=${LINK##*/} # delete the shortest match of .html from the right of the filename, to give the name of the link (equivalent to `echo $LINKNAME | sed -e 's/.html//g'` LINKNAME=${LINKFILE%.html} echo "<a href="$LINK">$LINKNAME</a> |" }
# set the variables to detect a title change PREVTITLE="" TITLE=""
# start processing STDIN while read line; do # deletes the longest match of /* from the right of the path, to generate the category title, equivalent to `echo $link | cut -d/ -f1` TITLE=${line%%/*} if [ "$TITLE" != "$PREVTITLE" ]; then if [ "$PREVTITLE" != "" ]; then # only print the <br> on title change and not at start of loop. ending fi title $TITLE PREVTITLE=$TITLE fi link $line done ###########################################
n 3 July 2010 11:25, Sam Sharpe lists.redhat@samsharpe.net wrote:
On 3 July 2010 11:09, Jozsi Avadkan jozsi.avadkan@gmail.com wrote:
it will be a site, were i put my notes
I'll give you the benefit of the doubt based on the fact a quick Google search says you ask questions a lot and they don't all look like homework ;o)
If you have the filenames in a file, you can do this:
<snip>
# delete the longest match of */ from the left side of the path, to give the filename (equivalent to running `basename $LINK`)
That didn't line-wrap very well... here is the pastebin version:
On Sat, Jul 3, 2010 at 5:07 AM, Jozsi Avadkan jozsi.avadkan@gmail.com wrote:
input: http://pastebin.com/raw.php?i=MqPXZwc3
output: http://pastebin.com/raw.php?i=8QCkp4yv
it will be a long day.. :D
could someone please help with it?
i have to make a "one liner" that get's the input, and gives the mentioned output.
It's a rather simple bash script, but not a one-liner unless you don't count semicolons..
In p-code:
OLD_FOO=DUMMY
for each line in the input file FOO=dirname BAR=basename IF FOO != OLD_FOO print a header
print HREF line
OLD_FOO=foo endfor
On Sat, 2010-07-03 at 11:07 +0200, Jozsi Avadkan wrote:
input: http://pastebin.com/raw.php?i=MqPXZwc3
output: http://pastebin.com/raw.php?i=8QCkp4yv
it will be a long day.. :D
Not likely. Obviously, you must replace lynx with cat <file>.
lynx -dump http://pastebin.com/raw.php?i=MqPXZwc3%7Csed -r 's/([^/]*)/(.*).html/<br><font size=4>\1</font><br>\n<a href="\1\/\2.html">\2</a> |/g'
Understood? I'll not be available during football matches.
Regards. ---------------------------------------------- Rodolfo Alcazar Portillo - nospaze@gmail.com otbits.blogspot.com / counter.li.org: #367962 ---------------------------------------------- - "Bother," said Pooh, "Eeyore, ready two photon torpedoes and lock phasers on the Heffalump, Piglet, meet me in transporter room three." Robert Billing
On 3 July 2010 14:16, Rodolfo Alcazar Portillo nospaze@gmail.com wrote:
On Sat, 2010-07-03 at 11:07 +0200, Jozsi Avadkan wrote:
input: http://pastebin.com/raw.php?i=MqPXZwc3
output: http://pastebin.com/raw.php?i=8QCkp4yv
it will be a long day.. :D
Not likely. Obviously, you must replace lynx with cat <file>.
lynx -dump http://pastebin.com/raw.php?i=MqPXZwc3%7Csed -r 's/([^/]*)/(.*).html/<br><font size=4>\1</font><br>\n<a href="\1\/\2.html">\2</a> |/g'
I'm afraid that's a fail - it doesn't match the desired output.
It's quite cool, however:
1) It needs to place a "<br>\n" before everything except the initial header line with the <font> tag. 2) It repeats the header above each link. Jozsi wanted the header only above the first occurrence to group the links.
On Sat, 2010-07-03 at 15:20 +0100, Sam Sharpe wrote:
On 3 July 2010 14:16, Rodolfo Alcazar Portillo nospaze@gmail.com wrote:
On Sat, 2010-07-03 at 11:07 +0200, Jozsi Avadkan wrote:
input: http://pastebin.com/raw.php?i=MqPXZwc3
output: http://pastebin.com/raw.php?i=8QCkp4yv
it will be a long day.. :D
Not likely. Obviously, you must replace lynx with cat <file>.
lynx -dump http://pastebin.com/raw.php?i=MqPXZwc3%7Csed -r 's/([^/]*)/(.*).html/<br><font size=4>\1</font><br>\n<a href="\1\/\2.html">\2</a> |/g'
I'm afraid that's a fail - it doesn't match the desired output.
Oh, oh, oh, oh. Didn't check the grouping. There you go (one-liner, just using one FOR):
FILE=$(lynx -dump http://pastebin.com/raw.php?i=MqPXZwc3); SETS=$(echo "$INPUT"|cut -f1 -d/|uniq); for S in $SETS; do echo "<br><font size=4>$S</font><br>"; echo "$FILE"|grep "^$S"|sed -r "s/(.*)/(.*).html/<a href="\1/\2.html">\2</a>|/g"; echo "<br>"; done
Bye! ---------------------------------------------- Rodolfo Alcazar Portillo - nospaze@gmail.com otbits.blogspot.com / counter.li.org: #367962 ---------------------------------------------- Programming is like sex: One mistake and you're providing support for a lifetime. -- ?
my own solution: http://pastebin.com/raw.php?i=kqQXCpD5
input: http://pastebin.com/raw.php?i=MqPXZwc3
output: http://pastebin.com/raw.php?i=8QCkp4yv
it will be a long day.. :D
could someone please help with it?
i have to make a "one liner" that get's the input, and gives the mentioned output.