Modify text file if found multiple pattern match for every line.


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Modify text file if found multiple pattern match for every line.
# 15  
Old 08-23-2018
The s/ / / do the substitutions.
If you want to not have substitions for a certain string, then branch to the Loop before, i.e. have another line
Code:
    /boards /bLoop

(If boards is found then branch to Loop.)
If everything looks okay, then redirect the output to a file. And if successful, copy it back to the original file.
Code:
sed '
...
' file > file.new &&
cp file.new file &&
rm file.new

The && chain the next command only if the preceding command was successful (exit 0).
This User Gave Thanks to MadeInGermany For This Post:
# 16  
Old 08-23-2018
Try
Code:
sed -e '0,/! IPG:/{/! IPG:/a\
\

testplan generation off' -e '; }; /! IPG:/ b;' -e 's/;/; permanent,/; t;' -e '/^ *$/!s/$/; permanent/' file

This User Gave Thanks to RudiC For This Post:
# 17  
Old 09-04-2018
Code:
cp testorder testorder_ori

sed '
  /^! IPG: /{
    a\
\
testplan generation off
    :Loop
    n
    /^boards /bLoop
    /^! IPG: /bLoop
    /; permanent/bLoop
    /^ *$/bLoop
    s/; /&permanent, /
    tLoop
    s/$/; permanent/
    bLoop
  }
' testorder_ori >testorder

above is the code that able to work, thank a lot.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match Pattern and print pattern and multiple lines into one line

Hello Experts , require help . See below output: File inputs ------------------------------------------ Server Host = mike id rl images allocated last updated density vimages expiration last read <------- STATUS ------->... (4 Replies)
Discussion started by: tigerhills
4 Replies

2. Shell Programming and Scripting

Multiple pattern match and print the output in a single line

I need to match two patterns in a log file and need to get the next line of the one of the pattern (out of two patterns) that is matched, finally need to print these three values in a single line. Sample Log: 2013/06/11 14:29:04 <0999> (725102) Processing batch 02_1231324 2013/06/11... (4 Replies)
Discussion started by: rpm120
4 Replies

3. Shell Programming and Scripting

Append text on particular line after pattern found

hi, i have /etc/inittab, I want to add another line after that when i find a pattern "l6:6:wait:/etc/rc.d/rc 6". original l6:6:wait:/etc/rc.d/rc 6 after-change l6:6:wait:/etc/rc.d/rc 6 /sbin/if-pp-to-cng (3 Replies)
Discussion started by: learnbash
3 Replies

4. Shell Programming and Scripting

Displaying text till pattern match found in a line

Hi All, From the below line if we want to display all the text till found pattern dot/. I was trying with the below code but couldn't able to print text before the pattern. it display texts which is found after pattern. awk '/assed/{print;getline;print}' file_name | sed 's/^*. *//' input... (4 Replies)
Discussion started by: Optimus81
4 Replies

5. Shell Programming and Scripting

Modify one line in a plain text file

Hi everyone, I want to know, if there is a way to modify one line in a text file with unix script, with out re-writing all the file. For example, i have this file: CONFIGURATION_1=XXXX CONFIGURATION_2=YYYY CONFIGURATION_3=ZZZZ supose i have a command or function "modify" that... (7 Replies)
Discussion started by: Xedrox
7 Replies

6. Shell Programming and Scripting

To add a new line with specific text after the pattern is found using sed

hi guys, im trying to add the following line in my xml file <dbrollbacksegs <oa_var="s_db_rollback_segs">NOROLLBACK</dbrollbacksegs> when ever i find the following line <dbsharedpool oa_var="s_dbsharedpool_size">300000000</dbsharedpool> I have succedded till adding a new line... (1 Reply)
Discussion started by: smarlaku
1 Replies

7. Shell Programming and Scripting

Modify a file by another file: add new line and variable after string is found

hello, I have problem with writing/adjusting a shell script. I searched forum and unfortunately couldn't write scipt based on the information I found. I never wtire such so it's hard for me and I do need to modify one script immediately. case looks like: 1. 'file' that needs to be modified... (3 Replies)
Discussion started by: bipbip
3 Replies

8. Shell Programming and Scripting

Need help to modify perl script: Text file with line and more than 1 space

Dear Friends, I am beginner in Perl and trying to find the problem in a script. Kindly help me to modify the script. My script is not giving the output for the last field and followed text (LA: Language English). Input file & script as follows: Input file: Thu Mar 19 2:34:14 EDT 2009 STC... (3 Replies)
Discussion started by: srsahu75
3 Replies

9. Shell Programming and Scripting

Modify Specific Line of a Text File

Given a text file, how do you add a line of text after a specific line number? I believe I would want to use "sed" but I am unsure of the syntax. Thank you. Mike (5 Replies)
Discussion started by: msb65
5 Replies

10. Shell Programming and Scripting

Concatenating multiple lines to one line if match pattern

Hi all, I've been working on a script which I have hit a road block now. I have written a script using sed to extract the below data and pumped into another file: Severity............: MAJORWARNING Summary: System temperature is out of normal range. Severity............: MAJORWARNING... (13 Replies)
Discussion started by: phixsius
13 Replies
Login or Register to Ask a Question