Sponsored Content
Top Forums Shell Programming and Scripting Find a text and if condition matches then replace it Post 303022859 by singhhe on Saturday 8th of September 2018 03:18:44 PM
Old 09-08-2018
Find a text and if condition matches then replace it

Need a script that can find text in a file and replace it accordingly.
This is the file I have:

Code:
while IFS=',' read -r f1 f2 f3
do
{
nohup /home/testuser/dbmaintenance/sys_offline_maintenance.sh $f1 $f2 $f3 > $f2.out &
}
done < "/home/testuser/dbmaintenance/week1offlineserver.txt"

In this file I need a script that can look for the number after week in week1offlineserver.txt and replace it like: If number is 1, change it to 2, if number is 2 then to 3 and if it is 3 then to 4 and if it is 4 then to 1.

Last edited by Scrutinizer; 09-08-2018 at 04:35 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Find and replace text

test 100 abc test 134 bcd test 356 cdf test 831 dfg test 720 fgh Please advise how can I replace the abc, bcd....with ABC, BCD.... (1 Reply)
Discussion started by: bobo
1 Replies

2. UNIX for Dummies Questions & Answers

Find and replace text PLEASE HELP

Dear friends please help, I have a large data file with few hundred lines. A small example is shown below: datafile is a file with few hundred lines with the third column has many different character stings: test 100 abc test 134 bcd test 356 cdf test 831 dfg test 720 fgh I need to... (6 Replies)
Discussion started by: bobo
6 Replies

3. Shell Programming and Scripting

find text but replace a text beside it

I have an html file that looks like this (this is just a part of the html file): <td colspan="3" rowspan="1" style="text-align: center; background-color: rgb(<!-- IDENTIFIER1 -->51, 255, 51);"><small><!-- IDENTIFIER2 -->UP</small></td> This is to automatically update the status of the... (4 Replies)
Discussion started by: The One
4 Replies

4. Shell Programming and Scripting

Need to find a string, check the next line, and if it matches certain criteria, replace it with a s

Hey Fellas. I am new to scripting. I have searched through the forums and found a lot of good info, but I can't seem to get any of it to work together. I am trying to find a particular sting in a file, and if the next string matches certain criteria, replace it with a string from a csv... (6 Replies)
Discussion started by: midniteslice
6 Replies

5. Shell Programming and Scripting

Find and add/replace text in text files

Hi. I would like to have experts help on below action. I have text files in which page nubmers exists in form like PAGE : 1 PAGE : 2 PAGE : 3 and so on there is other text too. I would like to know is it possible to check the last occurance of Page... (6 Replies)
Discussion started by: lodhi1978
6 Replies

6. Shell Programming and Scripting

Replace text inside XML file based on condition

Hi All, I want to change the name as SEQ_13 ie., <Property Name="Name">SEQ_13</Property> when the Stage Type is PxSequentialFile ie., <Property Name="StageType">PxSequentialFile</Property> :wall: Input.XML <Main> <Record Identifier="V0S13" Type="CustomStage" Readonly="0">... (3 Replies)
Discussion started by: kmsekhar
3 Replies

7. Emergency UNIX and Linux Support

Find a line using a condition and replace a string in that line

Hello, I have a 100 line code. I have given a sample of it below: ABC*654654*1*54.54*21.2*87*1*654654654654 CCC*FS*FS*SFD*DSF GGG*FGH*CGB*FBDFG*FGDG ABC*654654*1*57.84*45.4*88*2*6546546545 CCC*WSF*SG*FGH*GHJ ADA*AF*SFG*DFGH*FGH*FGTH I need to select the line starting with "ABC" its... (3 Replies)
Discussion started by: nithins007
3 Replies

8. Shell Programming and Scripting

Send email if the condition matches

Hello everyone, I am trying to create function or script to send email from an address book file. Here is the file format i have, Susan:Miller:M:123 Main Street:Philadelphia:PA:17101:666-645-6666:Susan.Miller@gmail.com:07/12/1979 Robert:Langan:S:32 North Avenue:San... (5 Replies)
Discussion started by: asistant
5 Replies

9. Shell Programming and Scripting

Shell Script @ Find a key word and If the key word matches then replace next 7 lines only

Hi All, I have a XML file which is looks like as below. <<please see the attachment >> <?xml version="1.0" encoding="UTF-8"?> <esites> <esite> <name>XXX.com</name> <storeId>10001</storeId> <module> ... (4 Replies)
Discussion started by: Rajeev_hbk
4 Replies

10. Shell Programming and Scripting

Grepping only if condition matches

Dear Friends, I have a flat file which is as follows $cat sample 123,456,1,1,1,1 sdfas,345,1,1,1,1 dfgd,234,2,3,4,1 ggffgr,234,4,3,2,1 jkhu,354.1,1,1,1 $ I want to get output of only those lines which has '1' in 3 to 5 position. So I want output as follows 123,456,1,1,1,1... (8 Replies)
Discussion started by: anushree.a
8 Replies
Mojo::DOM(3pm)						User Contributed Perl Documentation					    Mojo::DOM(3pm)

NAME
Mojo::DOM - Minimalistic HTML5/XML DOM parser with CSS3 selectors SYNOPSIS
use Mojo::DOM; # Parse my $dom = Mojo::DOM->new('<div><p id="a">A</p><p id="b">B</p></div>'); # Find my $b = $dom->at('#b'); say $b->text; # Walk say $dom->div->p->[0]->text; say $dom->div->children('p')->first->{id}; # Iterate $dom->find('p[id]')->each(sub { say shift->{id} }); # Loop for my $e ($dom->find('p[id]')->each) { say $e->text; } # Modify $dom->div->p->[1]->append('<p id="c">C</p>'); # Render say $dom; DESCRIPTION
Mojo::DOM is a minimalistic and relaxed HTML5/XML DOM parser with CSS3 selector support. It will even try to interpret broken XML, so you should not use it for validation. CASE SENSITIVITY
Mojo::DOM defaults to HTML5 semantics, that means all tags and attributes are lowercased and selectors need to be lowercase as well. my $dom = Mojo::DOM->new('<P ID="greeting">Hi!</P>'); say $dom->at('p')->text; say $dom->p->{id}; If XML processing instructions are found, the parser will automatically switch into XML mode and everything becomes case sensitive. my $dom = Mojo::DOM->new('<?xml version="1.0"?><P ID="greeting">Hi!</P>'); say $dom->at('P')->text; say $dom->P->{ID}; XML detection can also be disabled with the "xml" method. # Force XML semantics $dom->xml(1); # Force HTML5 semantics $dom->xml(0); METHODS
Mojo::DOM implements the following methods. "new" my $dom = Mojo::DOM->new; my $dom = Mojo::DOM->new('<foo bar="baz">test</foo>'); Construct a new Mojo::DOM object. "all_text" my $trimmed = $dom->all_text; my $untrimmed = $dom->all_text(0); Extract all text content from DOM structure, smart whitespace trimming is enabled by default. # "foo bar baz" $dom->parse("<div>foo <p>bar</p>baz </div>")->div->all_text; # "foo barbaz " $dom->parse("<div>foo <p>bar</p>baz </div>")->div->all_text(0); "append" $dom = $dom->append('<p>Hi!</p>'); Append to element. # "<div><h1>A</h1><h2>B</h2></div>" $dom->parse('<div><h1>A</h1></div>')->at('h1')->append('<h2>B</h2>'); "append_content" $dom = $dom->append_content('<p>Hi!</p>'); Append to element content. # "<div><h1>AB</h1></div>" $dom->parse('<div><h1>A</h1></div>')->at('h1')->append_content('B'); "at" my $result = $dom->at('html title'); Find a single element with CSS3 selectors. All selectors from Mojo::DOM::CSS are supported. # Find first element with "svg" namespace definition my $namespace = $dom->at('[xmlns:svg]')->{'xmlns:svg'}; "attrs" my $attrs = $dom->attrs; my $foo = $dom->attrs('foo'); $dom = $dom->attrs({foo => 'bar'}); $dom = $dom->attrs(foo => 'bar'); Element attributes. "charset" my $charset = $dom->charset; $dom = $dom->charset('UTF-8'); Alias for "charset" in Mojo::DOM::HTML. "children" my $collection = $dom->children; my $collection = $dom->children('div'); Return a Mojo::Collection object containing the children of this element, similar to "find". # Show type of random child element say $dom->children->shuffle->first->type; "content_xml" my $xml = $dom->content_xml; Render content of this element to XML. # "<b>test</b>" $dom->parse('<div><b>test</b></div>')->div->content_xml; "find" my $collection = $dom->find('html title'); Find elements with CSS3 selectors and return a Mojo::Collection object. All selectors from Mojo::DOM::CSS are supported. # Find a specific element and extract information my $id = $dom->find('div')->[23]{id}; # Extract information from multiple elements my @headers = $dom->find('h1, h2, h3')->map(sub { shift->text })->each; "namespace" my $namespace = $dom->namespace; Find element namespace. # Find namespace for an element with namespace prefix my $namespace = $dom->at('svg > svg:circle')->namespace; # Find namespace for an element that may or may not have a namespace prefix my $namespace = $dom->at('svg > circle')->namespace; "parent" my $parent = $dom->parent; Parent of element. "parse" $dom = $dom->parse('<foo bar="baz">test</foo>'); Alias for "parse" in Mojo::DOM::HTML. # Parse UTF-8 encoded XML my $dom = Mojo::DOM->new->charset('UTF-8')->xml(1)->parse($xml); "prepend" $dom = $dom->prepend('<p>Hi!</p>'); Prepend to element. # "<div><h1>A</h1><h2>B</h2></div>" $dom->parse('<div><h2>B</h2></div>')->at('h2')->prepend('<h1>A</h1>'); "prepend_content" $dom = $dom->prepend_content('<p>Hi!</p>'); Prepend to element content. # "<div><h2>AB</h2></div>" $dom->parse('<div><h2>B</h2></div>')->at('h2')->prepend_content('A'); "replace" $dom = $dom->replace('<div>test</div>'); Replace elements. # "<div><h2>B</h2></div>" $dom->parse('<div><h1>A</h1></div>')->at('h1')->replace('<h2>B</h2>'); "replace_content" $dom = $dom->replace_content('test'); Replace element content. # "<div><h1>B</h1></div>" $dom->parse('<div><h1>A</h1></div>')->at('h1')->replace_content('B'); "root" my $root = $dom->root; Find root node. "text" my $trimmed = $dom->text; my $untrimmed = $dom->text(0); Extract text content from element only (not including child elements), smart whitespace trimming is enabled by default. # "foo baz" $dom->parse("<div>foo <p>bar</p>baz </div>")->div->text; # "foo baz " $dom->parse("<div>foo <p>bar</p>baz </div>")->div->text(0); "text_after" my $trimmed = $dom->text_after; my $untrimmed = $dom->text_after(0); Extract text content immediately following element, smart whitespace trimming is enabled by default. # "baz" $dom->parse("<div>foo <p>bar</p>baz </div>")->div->p->text_after; # "baz " $dom->parse("<div>foo <p>bar</p>baz </div>")->div->p->text_after(0); "text_before" my $trimmed = $dom->text_before; my $untrimmed = $dom->text_before(0); Extract text content immediately preceding element, smart whitespace trimming is enabled by default. # "foo" $dom->parse("<div>foo <p>bar</p>baz </div>")->div->p->text_before; # "foo " $dom->parse("<div>foo <p>bar</p>baz </div>")->div->p->text_before(0); "to_xml" my $xml = $dom->to_xml; Render this element and its content to XML. # "<div><b>test</b></div>" $dom->parse('<div><b>test</b></div>')->div->to_xml; "tree" my $tree = $dom->tree; $dom = $dom->tree(['root', [qw(text lalala)]]); Alias for "tree" in Mojo::DOM::HTML. "type" my $type = $dom->type; $dom = $dom->type('div'); Element type. # List types of child elements $dom->children->each(sub { say $_->type }); "xml" my $xml = $dom->xml; $dom = $dom->xml(1); Alias for "xml" in Mojo::DOM::HTML. CHILD ELEMENTS
In addition to the methods above, many child elements are also automatically available as object methods, which return a Mojo::DOM or Mojo::Collection object, depending on number of children. say $dom->p->text; say $dom->div->[23]->text; $dom->div->each(sub { say $_->text }); ELEMENT ATTRIBUTES
Direct hash reference access to element attributes is also possible. say $dom->{foo}; say $dom->div->{id}; SEE ALSO
Mojolicious, Mojolicious::Guides, <http://mojolicio.us>. perl v5.14.2 2012-09-05 Mojo::DOM(3pm)
All times are GMT -4. The time now is 03:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy