Skip to content

Instantly share code, notes, and snippets.

@juanmsl
Created November 18, 2022 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanmsl/aca0caf626c53e36c3f9f33209a58569 to your computer and use it in GitHub Desktop.
Save juanmsl/aca0caf626c53e36c3f9f33209a58569 to your computer and use it in GitHub Desktop.
#!/bin/bash -e
echo "usage: $0 <txt file containing list of urls>"
inputFile=${1}
if [ $# -ne 1 ] || [ ! -f ${inputFile} ];then
echo 'check usage'
exit -1
fi
outputFile='bookmarks.html'
echo '<DL>' > $outputFile
NumLines=`wc -l ${inputFile} | cut -d' ' -f5`
currLineNum=0
inGroup="no"
for eachUrl in `cat ${inputFile}`
do
let currLineNum=${currLineNum}+1
urlTitle=`echo ${eachUrl} | rev | cut -d'/' -f1 | rev`
if [ -z ${urlTitle} ] || ([[ ${urlTitle} =~ "www" ]] && [[ ${urlTitle} =~ "com" ]]);then
urlTitle=`echo $eachUrl | cut -d'.' -f2`
echo " <DT><A HREF=\"${eachUrl}\">${urlTitle}</A>" >> $outputFile
else
echo "${urlTitle} (${currLineNum}/${NumLines})"
if [[ ${inGroup} == "no" ]]; then
inGroup="yes"
else
echo " </DL>" >> $outputFile
fi
echo " <DT><H3>${urlTitle}</H3>" >> $outputFile
echo " <DL>" >> $outputFile
fi
done
if [[ ${inGroup} == "yes" ]]; then
echo ' </DL>' >> $outputFile
fi
echo '</DL>' >> $outputFile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment