03-18-2020
You may try perl. When it comes to regex and string parsing, perl handles them beautifully. Of course, doesn't mean you don't have other options.
This User Gave Thanks to balajesuri For This Post:
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi, I am trying something like this: Let's say I have a file called File1 with contents:
x=-0.3
y=2.1
z=9.0
I have another file, File2, with contents:
xx=
yy=
zz=
(nothing after "="). What I want to do is get the value of x in File1 and set it to xx in File2, i.e., xx=-0.3. And the... (3 Replies)
Discussion started by: ommatidia
3 Replies
2. Shell Programming and Scripting
Hi,
I need to do an exact find and replace (I don't want to use regular expressions because the input comes from user). I want to find a line that matches the user's input text and replace it with an empty string.
For example, let's say the user enters I love "Unix" and the contents of the... (2 Replies)
Discussion started by: srikanths
2 Replies
3. Shell Programming and Scripting
Hello
I have this regular expression:
</book>(?:\n)<collection>(.*)</collectioninfo>
And I have this peace of text on a FILE
<book bookid="3" title="the title 3" remaining = "50" price="100">
<reader readerid="1"><!]></reader>
<reader readerid="2"><!]></reader>
<reader... (1 Reply)
Discussion started by: dirdamalah
1 Replies
4. UNIX for Dummies Questions & Answers
Hello,
I need help with using grep and regular expressions....
I have a long list of about 1000 lines of Chinese flashcards. Here's a small excerpt:
意文 yìwén (given name)
貴姓 guìxìng (honorable surname)
貴 guì (honorable)
姓 xìng (one's surname is; to be surnamed; surname)
呢 ne (interrogative... (2 Replies)
Discussion started by: arduino411
2 Replies
5. Linux
Hello everyone,
I am trying to do a simple script (shell or perl) for a bioinformatic problem, where I want to use a list from file2 and append this information to file1 (output).
Example:
File1
>Apple1
GAGACGATTTATATATAGAAGAGAG
>Banana2
CAGAGAGAGAGACCCCCCCCCCCC
File2
>Apple1 ... (2 Replies)
Discussion started by: herasj01
2 Replies
6. Shell Programming and Scripting
For reference i am still a newb at scripting, but i have what i think is a complex issue.
I need to run a FIND on / to identify all files and print them to >> $TEMPFILE
I need to avoid MVFS
I need to avoid /var/tmp/nastmp/
I was trying find / \( -type d -name nastmp -prune \) -a \( -fstype... (4 Replies)
Discussion started by: nitrobass24
4 Replies
7. Shell Programming and Scripting
Guys, need help.
I have a file that contains something like this:
abc
def
ghi
jkl
I want to print the first and last line of the file and the output should be in a single line.
so, output should be like this:
abc jkl (3 Replies)
Discussion started by: solidhelix08
3 Replies
8. UNIX for Advanced & Expert Users
Hi
Could you please advise how can one extract from the output of
find . -name "*.c" -print
only filenames in the current direcotry and not in its subdirectories?
I tried using (on Linux x86_64)
find . -name "*.c" -prune
but it is not giving correct output.
Whereas I am getting... (9 Replies)
Discussion started by: tinku981
9 Replies
9. Shell Programming and Scripting
Friends,
I have more than 1000 lines in text file which needs to be converted as UPPERCASE by adding _
com.sun.url=www.sun.com
com.ssl.port=808
com.ui.path=/apps/ssi
Expected output
com.sun.url=_COM.SUN.URL_
com.ssl.port=_COM.SSL.PORT_
com.ui.path=_COM.UI.PATH_
Thanks in... (4 Replies)
Discussion started by: baluchen
4 Replies
10. Shell Programming and Scripting
Hello
I am trying to write sed code where it will look through the text for lines with specific expression "Started by user" and when found, will also add the following line, and also lines with another expression "Finished:"
sed -n '/Started by user/, +1p, /Finished:/'... (4 Replies)
Discussion started by: dlesny
4 Replies
LEARN ABOUT DEBIAN
data::munge
Data::Munge(3pm) User Contributed Perl Documentation Data::Munge(3pm)
NAME
Data::Munge - various utility functions
SYNOPSIS
use Data::Munge;
my $re = list2re qw/foo bar baz/;
print byval { s/foo/bar/ } $text;
foo(mapval { chomp } @lines);
print replace('Apples are round, and apples are juicy.', qr/apples/i, 'oranges', 'g');
print replace('John Smith', qr/(w+)s+(w+)/, '$2, $1');
DESCRIPTION
This module defines a few generally useful utility functions. I got tired of redefining or working around them, so I wrote this module.
Functions
list2re LIST
Converts a list of strings to a regex that matches any of the strings. Especially useful in combination with "keys". Example:
my $re = list2re keys %hash;
$str =~ s/($re)/$hash{$1}/g;
byval BLOCK SCALAR
Takes a code block and a value, runs the block with $_ set to that value, and returns the final value of $_. The global value of $_ is
not affected. $_ isn't aliased to the input value either, so modifying $_ in the block will not affect the passed in value. Example:
foo(byval { s/!/?/g } $str);
# Calls foo() with the value of $str, but all '!' have been replaced by '?'.
# $str itself is not modified.
mapval BLOCK LIST
Works like a combination of "map" and "byval"; i.e. it behaves like "map", but $_ is a copy, not aliased to the current element, and
the return value is taken from $_ again (it ignores the value returned by the block). Example:
my @foo = mapval { chomp } @bar;
# @foo contains a copy of @bar where all elements have been chomp'd.
# This could also be written as chomp(my @foo = @bar); but that's not
# always possible.
submatches
Returns a list of the strings captured by the last successful pattern match. Normally you don't need this function because this is
exactly what "m//" returns in list context. However, "submatches" also works in other contexts such as the RHS of "s//.../e".
replace STRING, REGEX, REPLACEMENT, FLAG
replace STRING, REGEX, REPLACEMENT
A clone of javascript's "String.prototype.replace". It works almost the same as "byval { s/REGEX/REPLACEMENT/FLAG } STRING", but with a
few important differences. REGEX can be a string or a compiled "qr//" object. REPLACEMENT can be a string or a subroutine reference. If
it's a string, it can contain the following replacement patterns:
$$ Inserts a '$'.
$& Inserts the matched substring.
$` Inserts the substring preceding the match.
$' Inserts the substring following the match.
$N (where N is a digit)
Inserts the substring matched by the Nth capturing group.
${N} (where N is one or more digits)
Inserts the substring matched by the Nth capturing group.
Note that these aren't variables; they're character sequences interpreted by "replace".
If REPLACEMENT is a subroutine reference, it's called with the following arguments: First the matched substring (like $& above), then
the contents of the capture buffers (as returned by "submatches"), then the offset where the pattern matched (like "$-[0]", see "@-" in
perlvar), then the STRING. The return value will be inserted in place of the matched substring.
Normally only the first occurrence of REGEX is replaced. If FLAG is present, it must be 'g' and causes all occurrences to be replaced.
AUTHOR
Lukas Mai, "<l.mai at web.de>"
COPYRIGHT & LICENSE
Copyright 2009-2011 Lukas Mai.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as
published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
perl v5.12.4 2011-08-03 Data::Munge(3pm)