Tagged Questions
1
vote
2answers
34 views
Trimming one part if equal to another part?
I use an e-mail quote attribution string like this:
On dd mmm yyyy hh:mm +hhmm, from info@example.org (Example Dot Org):
where info@example.org is the sender's e-mail address and Example Dot Org is ...
4
votes
3answers
136 views
Delete XML node containing certain element
I want to remove all Placemarks from a KML file that contain the element <tessellate>. The following block should be wholly removed:
<Placemark>
...
1
vote
3answers
169 views
awk, sed, grep, perl… which to print out in this case?
I have this syntax in a file (http response times from analog):
<thead><tr><th class="x">seconds</th><th class="R">reqs</th><th ...
2
votes
2answers
500 views
How to do a regex search in a UTF-16LE file while in a UTF-8 locale?
EDIT: Due to a comment Warren Young made, it made me realize that I was not clear on one quite relevant point. My search string is already in UTF-16LE order (not in Unicode Codepoint order, which is ...
0
votes
2answers
161 views
Difference in regular expression handling between Perl, Kikki, and Kodos
#!/usr/bin/perl
$mystring = "[2004/04/13] The date of this article.";
if($mystring =~ m/(\d+)/) {
print "The first number is $1.";
}
Perl returns 2004, but Kiki and Kodos return /04/. Why ...
2
votes
4answers
893 views
How to insert the content of a file into another file (if regexp) in shell/perl
File1 Contents:
line1-file1 "1"
line2-file1 "2"
line3-file1 "3"
line4-file1 "4"
File2 Contents:
line1-file2 "25"
line2-file2 "24"
Pointer-file2 "23"
...
2
votes
1answer
477 views
Escaping of meta characters in basic/extended posix regex strings in grep
Is it possible to escape all meta characters of a string inside a variable before passing it to grep? I know similar question has been asked before on SE
(here) and also a good explanation here, but I ...
4
votes
2answers
607 views
Parsing XML from a shell script
I have a datafile like this:
<Key name="com.ahsay.afc.cpf.UserGroup" content="" allowMultiple="Y">
<Value name="rsv-id" inheritParentAttribute="Y" type="string" data="1328200856753" ...
2
votes
4answers
1k views
Extract IP address from a string
The Linux host command returns:
hostA.domain.com has address xx.xxx.xxx.xx
How do I get just the IP address and put it in the $ipaddr variable?
open(FILE, "hostlist.txt") or die("Unable to open ...
8
votes
6answers
727 views
Delete lines beginning with #
How do I delete lines beginning with a #, given that there can be whitespace on the left and right of the #?
# Master socket provides access to userdb information. It's typically
5
votes
3answers
527 views
Regex & Sed/Perl: Match word that ISN'T preceded by another word
I'd like to use sed or perl to replace all occurrences of a word that doesn't have a certain word in front of it.
For example, I have a text file that contains a plot of a movie and I want to replace ...
2
votes
2answers
186 views
perl regex replacing globally when global not selected
I'm using Ubuntu 11.04 and wrote a small script that searches within text files for certain "tokens" and replaces with some a prewritten snippet from a template file of the same name.
The text files ...
3
votes
3answers
164 views
What does . match?
In working with regular expressions, I have been told that a dot character . will match everything.
Except for newlines \n.
Are there any other exceptions? What about the NUL character \0, or the ...
4
votes
1answer
473 views
Renaming files to have lower case extensions with 'rename'
I'm trying to currently rename a large set of files and have been using quite kludgy methods to do so, such as:
rename 's:(.*)\.MOV:$1.mov:g' *.MOV
rename 's:(.*)\.JPG:$1.jpg:g' *.JPG
What I'd ...
