mirror of
https://github.com/thewesker/greptweet.git
synced 2025-12-22 13:01:06 -05:00
peel out expand urls code
This commit is contained in:
18
expand-urls.sh
Executable file
18
expand-urls.sh
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# vim: set ts=4 sw=4
|
||||||
|
|
||||||
|
test -s $1 || exit
|
||||||
|
test ${1##*.} = 'txt' || exit
|
||||||
|
|
||||||
|
temp=$(mktemp "$1.XXXX")
|
||||||
|
|
||||||
|
IFS='|'
|
||||||
|
while read -r id date text
|
||||||
|
do
|
||||||
|
url=$(echo $text | grep --only-matching --perl-regexp "http(s?):\/\/[^ \"\(\)\<\>]*")
|
||||||
|
expandedURL=$(curl "$url" -m5 -s -L -I -o /dev/null -w '%{url_effective}')
|
||||||
|
t=${text/$url/$expandedURL}
|
||||||
|
echo "$id|$date|$t"
|
||||||
|
done < $1 > $temp
|
||||||
|
|
||||||
|
mv $temp $1
|
||||||
Reference in New Issue
Block a user