Thursday, September 1, 2016
AWK: Hashtag Safe String Function
Command:
$ cat twitter_hash_safe_string.awk
Result:
function twitter_hash_safe_string(hashStr)
{
gsub(/^[0-9]+/,"", hashStr);
gsub(" ", "", hashStr);
gsub("\\.", "", hashStr);
gsub("'", "", hashStr);
gsub("%", "", hashStr);
gsub(/"/, "", hashStr);
gsub("\\(", "", hashStr);
gsub("\\)", "", hashStr);
gsub("&", "And", hashStr);
gsub("-", "", hashStr);
gsub("=", "", hashStr);
gsub(">", "", hashStr);
gsub("<", "", hashStr);
gsub("\\$", "S", hashStr);
gsub("\\/", " #", hashStr);
gsub(",", " #", hashStr);
gsub(":", " #", hashStr);
gsub(";", " #", hashStr);
return hashStr;
}
$ cat twitter_hash_safe_string.awk
Result:
function twitter_hash_safe_string(hashStr)
{
gsub(/^[0-9]+/,"", hashStr);
gsub(" ", "", hashStr);
gsub("\\.", "", hashStr);
gsub("'", "", hashStr);
gsub("%", "", hashStr);
gsub(/"/, "", hashStr);
gsub("\\(", "", hashStr);
gsub("\\)", "", hashStr);
gsub("&", "And", hashStr);
gsub("-", "", hashStr);
gsub("=", "", hashStr);
gsub(">", "", hashStr);
gsub("<", "", hashStr);
gsub("\\$", "S", hashStr);
gsub("\\/", " #", hashStr);
gsub(",", " #", hashStr);
gsub(":", " #", hashStr);
gsub(";", " #", hashStr);
return hashStr;
}
Wednesday, August 31, 2016
Tuesday, August 30, 2016
Ruby: Print Out Multiple Lines
Command:
$ printf "1,name1,address1\n2,name2,address2" | ruby -e "while status = STDIN.gets do = STDIN.gets do
print status
end"
Result:
1,name1,address1
2,name2,address2
$ printf "1,name1,address1\n2,name2,address2" | ruby -e "while status = STDIN.gets do = STDIN.gets do
print status
end"
Result:
1,name1,address1
2,name2,address2
Friday, August 26, 2016
Subscribe to:
Posts (Atom)