Sponsored Content
Top Forums Shell Programming and Scripting Replacing Block of lines in a text file Post 302283265 by zaxxon on Tuesday 3rd of February 2009 02:02:10 AM
Old 02-03-2009
One possible way:
Code:
awk '/^Function3$/ { x=1 } /^param/ && x == 1 {print $1,($2+3); next} /^Function4$/ { x=0 } {print}' infile
Function1
{
parameter 1
parameter 2
parameter 3
}
end

Function2
{
parameter 1
parameter 2
parameter 3
}
end

Function3
{
parameter 4
parameter 5
parameter 6
}
end

Function4
{
parameter 1
parameter 2
parameter 3
}
end

 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

replacing first line or lines in a file

hey guys, how do i replace only a line within a file without messing up the rest of the contents of the file? see, if possible can you guys give me a straight forward way to do this. i dont want a complex command. what i mean is i know i can accomplish this by using sed, well, i think i can,... (3 Replies)
Discussion started by: Terrible
3 Replies

2. Shell Programming and Scripting

replacing specific lines in a file

Hi there I have a file which has the lines # Serial number for hostid EXP_SERIAL_="" These lines could be anywhere in the file as far as line numbers go, I would like replace these two lines with # Serial number for hostid $var1 EXP_SERIAL_$var1="$var2" Is there a quick and simple... (6 Replies)
Discussion started by: hcclnoodles
6 Replies

3. Shell Programming and Scripting

Replacing lines in text files

Hi, I have 2 sets of text files. I need to take a field from a certain line in set 1 and put it in the same place in set b. The line appears once per file, in different places but is a set format and has the unique word "ANTENNA" in it and is always 81 characters long. Example from set a: ... (7 Replies)
Discussion started by: Jonny2Vests
7 Replies

4. Shell Programming and Scripting

Replacing Text in Text file

Hi Guys, I am needing some help writing a shell script to replace the following in a text file /opt/was/apps/was61 with some other path eg /usr/blan/blah/blah. I know that i can do it using sed or perl but just having difficulty writing the escape characters for it All Help... (3 Replies)
Discussion started by: cgilchrist
3 Replies

5. Shell Programming and Scripting

replacing text in a file, but...

Hi all, Very first post on this forums, hope you can help me with this scripting task. I have a big text file with over 3000 lines, some of those lines contain some text that I need to replace, lets say for simplicity the text to be replaced in those lines is "aaa" and I need it to replace it... (2 Replies)
Discussion started by: Angelseph
2 Replies

6. Shell Programming and Scripting

sed: Replacing two lines of text

I just created a file in vi, looks like this: Hello nobody nobody What I need is to have sed change the file so it looks like this: Hello everybody In other words, the sed query needs to look for both instances of "nobody" before it puts the word "everybody" on the first line. ... (2 Replies)
Discussion started by: calrog
2 Replies

7. UNIX for Advanced & Expert Users

Move a block of lines to file if string found in the block.

I have a "main" file which has blocks of data for each user defined by tags BEGIN and END. BEGIN ID_NUM:24879 USER:abc123 HOW:47M CMD1:xyz1 CMD2:arp2 STATE:active PROCESS:id60 END BEGIN ID_NUM:24880 USER:def123 HOW:4M CMD1:xyz1 CMD2:xyz2 STATE:running PROCESS:id64 END (7 Replies)
Discussion started by: grep_me
7 Replies

8. Shell Programming and Scripting

Printing a block of lines from a file, if that block does not contain two patterns using sed

I want to process a file block by block using sed, and if that block does not contain two patterns, then that complete block has to be printed. See below for the example data. ................................server 1............................... running process 1 running... (8 Replies)
Discussion started by: Kesavan
8 Replies

9. Shell Programming and Scripting

Matching and Replacing file lines starting with $

Here is the task that I was presented with: I am dealing with about a 10,000 line input deck file for an analysis. About 10 separate blocks of around 25 lines of code each need to be updated in the input deck. The input deck (deckToChange in the code below) comes with 2 separate files. File 1... (5 Replies)
Discussion started by: tiktak292
5 Replies

10. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies
Perl::Critic::PolicyParameter::Behavior::StringList(3)	User Contributed Perl Documentation Perl::Critic::PolicyParameter::Behavior::StringList(3)

NAME
Perl::Critic::PolicyParameter::Behavior::StringList - Actions appropriate for a parameter that is a list of strings. DESCRIPTION
Provides a standard set of functionality for a string list Perl::Critic::PolicyParameter so that the developer of a policy does not have to provide it her/himself. NOTE: Do not instantiate this class. Use the singleton instance held onto by Perl::Critic::PolicyParameter. INTERFACE SUPPORT
This is considered to be a non-public class. Its interface is subject to change without notice. METHODS
"initialize_parameter( $parameter, $specification )" Plug in the functionality this behavior provides into the parameter, based upon the configuration provided by the specification. This behavior looks for one configuration item: always_present_values Optional. Values that should always be included, regardless of what the configuration of the parameter specifies, as an array reference. "generate_parameter_description( $parameter )" Create a description of the parameter, based upon the description on the parameter itself, but enhancing it with information from this behavior. In this specific case, the always present values are added at the end. AUTHOR
Elliot Shank <perl@galumph.com> COPYRIGHT
Copyright (c) 2006-2011 Elliot Shank. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module. perl v5.16.3 2014-06-09 Perl::Critic::PolicyParameter::Behavior::StringList(3)
All times are GMT -4. The time now is 05:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy