Sponsored Content
Top Forums Shell Programming and Scripting Automating find and replace REGEX expressions in a script Post 303045492 by bedtime on Friday 27th of March 2020 04:39:27 PM
Old 03-27-2020
Quote:
Originally Posted by balajesuri
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.
Thank you. I've done just that. Perl seems to be the perfect tool for this issue.


Sorry for the late reply.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

automating file search and replace text

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

A simple find and replace without using any regex (bash)

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

Search Replace with regular expressions

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

Regular Expressions -- Find spaces outside

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

A find and replace script

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

FIND w/ multiple expressions

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

Find 2 expressions then print in a single line

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

Using find and regular expressions

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

Find and Replace in Shell script

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

sed find multiple expressions plus next next line

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
Util(3pm)						User Contributed Perl Documentation						 Util(3pm)

NAME
Taint::Util - Test for and flip the taint flag without regex matches or "eval" SYNOPSIS
#!/usr/bin/env perl -T use Taint::Util; # eek! untaint $ENV{PATH}; # $sv now tainted under taint mode (-T) taint(my $sv = "hlagh"); # Untaint $sv again untaint $sv if tainted $sv; DESCRIPTION
Wraps perl's internal routines for checking and setting the taint flag and thus does not rely on regular expressions for untainting or odd tricks involving "eval" and "kill" for checking whether data is tainted, instead it checks and flips a flag on the scalar in-place. FUNCTIONS
tainted Returns a boolean indicating whether a scalar is tainted. Always false when not under taint mode. taint & untaint Taints or untaints given values, arrays will be flattened and their elements tainted, likewise with the values of hashes (keys can't be tainted, see perlsec). Returns no value (which evaluates to false). untaint(%ENV); # Untaints the environment taint(my @hlagh = qw(a o e u)); # elements of @hlagh now tainted References (being scalars) can also be tainted, a stringified reference reference raises an error where a tainted scalar would: taint(my $ar = @hlagh); system echo => $ar; # err: Insecure dependency in system This feature is used by perl internally to taint the blessed object "qr//" stringifies to. taint(my $str = "oh noes"); my $re = qr/$str/; system echo => $re; # err: Insecure dependency in system This does not mean that tainted blessed objects with overloaded stringification via overload need return a tainted object since those objects may return a non-tainted scalar when stringified (see t/usage.t for an example). The internal handling of "qr//" however ensures that this holds true. File handles can also be tainted, but this is pretty useless as the handle itself and not lines retrieved from it will be tainted, see the next section for details. taint(*DATA); # *DATA tainted my $ln = <DATA>; # $ln not tainted About tainting in Perl Since this module is a low level interface that directly exposes the internal "SvTAINTED*" functions it also presents new and exciting ways for shooting yourself in the foot. Tainting in Perl was always meant to be used for potentially hostile external data passed to the program. Perl is passed a soup of strings from the outside; it never receives any complex datatypes directly. For instance, you might get tainted hash keys in %ENV or tainted strings from *STDIN, but you'll never get a tainted Hash reference or a tainted subroutine. Internally, the perl compiler sets the taint flag on external data in a select few functions mainly having to do with IO and string operations. For example, the "ucfirst" function will manually set a tainted flag on its newly created string depending on whether the original was tainted or not. However, since Taint::Util is exposing some of perl's guts, things get more complex. Internally, tainting is implemented via perl's MAGIC facility, which allows you to attach attach magic to any scalar, but since perl doesn't liberally taint scalars it's there to back you up if you do. You can "taint(*DATA)" and "tainted(*DATA)" will subsequently be true but if you read from the filehandle via "<DATA>" you'll get untainted data back. As you might have guessed this is completely useless. The test file t/usage.t highlights some of these edge cases. Back in the real world, the only reason tainting makes sense is because perl will back you up when you use it, e.g. it will slap your hand if you try to pass a tainted value to system(). If you taint references, perl doesn't offer that protection, because it doesn't know anything about tainted references since it would never create one. The things that do work like the stringification of "taint($t = [])" (i.e. "ARRAY(0x11a5d48)") being tainted only work incidentally. But I'm not going to stop you. By all means, have at it! Just don't expect it to do anything more useful than warming up your computer. See RT #53988 <https://rt.cpan.org/Ticket/Display.html?id=53988> for the bug that inspired this section. EXPORTS
Exports "tainted", "taint" and "untaint" by default. Individual functions can be exported by specifying them in the "use" list, to export none use "()". HISTORY
I wrote this when implementing re::engine::Plugin so that someone writing a custom regex engine with it wouldn't have to rely on perl regexps for untainting capture variables, which would be a bit odd. SEE ALSO
perlsec AUTHOR
var Arnfjoer` Bjarmason <avar@cpan.org> LICENSE
Copyright 2007-2010 var Arnfjoer` Bjarmason. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2010-03-17 Util(3pm)
All times are GMT -4. The time now is 12:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy