I need script to add quotes in url string from url.txt
from http://www.site.com/info.xx
to "http://www.site.com/info.xx"
I need script to add quotes in url string from url.txt
from http://www.site.com/info.xx
to "http://www.site.com/info.xx"
url = '"%s"' % url
Example:
line = 'http://www.site.com/info.xx \n'
url = '"%s"' % line.strip()
print url # "http://www.site.com/info.xx"
Remember, adding a backslash before a quotation mark will escape it and therefore won't end the string.
write one...
perl is my favourite scripting language... it appears you may prefer Python.
just read in the file and add \" before and after it..
this is pretty easy in perl.
this seems more like a request than a question... should this be on stackoverflow?
url = '"%s"' % url
Example:
>>> url = "http://www.site.com/info.xx"
>>> print url
http://www.site.com/info.xx
>>> url = '"%s"' % url
>>> print url
"http://www.site.com/info.xx"
>>>
Parsing it from a file:
from __future__ import with_statement
def parseUrlsTXT(filename):
with open(filename, 'r') as f:
for line in f.readlines():
url = '"%s"' % line[:-1]
print url
Usage:
parseUrlsTXT('/your/dir/path/URLs.txt')
If 'url.txt
' contains a list of urls, one url per line then:
quote the first non-whitespace character sequence:
$ perl -pe"s~\S+~\"$&\"~" url.txt
or trim whitespaces and quote the rest:
$ perl -nE"$_=trim; say qq(\"$_\")" url.txt
A simple Perl script:
#!/usr/bin/perl
use strict;
use warnings;
while (my $line = <>) {
$line =~ s/\s*(.*)\s*/$1/;
print qq/"$line"\n/;
}