Sponsored Content
Top Forums Shell Programming and Scripting Change specific ip address in a file Post 302415907 by rugdog on Friday 23rd of April 2010 04:48:14 PM
Old 04-23-2010
in the case of substituting a env var, do an export of the var, before the script:

Code:
export VAR=12.12.12.12.

perl -i -ne's/(ip=.+)(ip=.+?,)/$1ip=$ENV{VAR},/;print' file

as for adding back
Code:
perl -i -ne's/(ip=.+vifname=.+)(vifname=.+)/$1ip=$ENV{VAR},$2/;print' file


Last edited by Scott; 04-23-2010 at 05:59 PM.. Reason: Code tags, PLEASE!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to change a specific character in a file

Hi, I have a data file with following structure: a|b|c|d|3|f1|f2|f3 a|b|c|d|5|f1|f2|f3|f4|f5 I want to change this data to: a|b|c|d|3|f1;f2;f3 a|b|c|d|5|f1;f2;f3;f4;f5 Data in column 5 tells the number of following fields. All fields delimiter after the 5th column needs to be... (6 Replies)
Discussion started by: sdubey
6 Replies

2. UNIX for Dummies Questions & Answers

Change Specific Line of a File

Hi everyone, I am attempting to do something that should be very simple. How do I replace a specific line of a file with different text, and then save that file to its original name? I believe I want to use the sed command with the c option, but I after trying many times, I can't get the right... (10 Replies)
Discussion started by: msb65
10 Replies

3. UNIX for Dummies Questions & Answers

Script to change/find/delete/install a specific file

Hi Very much a newbie to UNIX & scripting, but have identified an area within work that would benefit from being automated, as its repeated manually very often, and it looks like the ideal first script! What I need to do is change directory to a users home (cd ~), and then find and remove a... (6 Replies)
Discussion started by: Great Uncle Kip
6 Replies

4. Shell Programming and Scripting

SED 4.1.4 - INI File Change Problem in Variables= in Specific [Sections] (Guru Help)

GNU sed version 4.1.4 on Windows XP SP3 from GnuWin32 I think that I've come across a seemingly simple text file change problem on a INI formatted file that I can't do with SED without side effects edge cases biting me. I've tried to think of various ways of doing this elegantly and quickly... (5 Replies)
Discussion started by: JakFrost
5 Replies

5. Shell Programming and Scripting

How to change a number on a specific lines in a file with shell?

Hello My problem is that I want to change some specific numbers in a file. It is like, 2009 10 3 2349 21.3 L 40.719 27.388 10.8 FRO 7 0.8 1.1LFRO 2.6CFRO 1.1LMAM1 GAP=157 1.69 5.7 5.9 5.8 0.5405E+01 0.4455E+00 0.1653E+02E STAT SP IPHASW D HRMM SECON CODA AMPLIT... (11 Replies)
Discussion started by: miriammiriam
11 Replies

6. UNIX for Dummies Questions & Answers

How can I search and change an specific string in a file

Dear All, New to Linux/Unix OS, my Linux version is 2010 x86_64 x86_64 x86_64 GNU/Linux As titled, I wonder if you can help to provide a solution to find and change an specific string in a file The file include a lots of data in following configuration but might be various in... (3 Replies)
Discussion started by: axel
3 Replies

7. Shell Programming and Scripting

how to change specific value for a entry in the file

Hello All, can someone please suggest me a one line command to change a specific value that is associated to an entry in the file. for example #more schedulefile quartz.job.manual.bonus.schedule=0 0 9 ? * * # it should be changed to #more schedulefile... (5 Replies)
Discussion started by: bobby320
5 Replies

8. Shell Programming and Scripting

To change Specific Lines in An XML file

hi Guys, this is my requirement, there is a huge xml file of this i have to change 3 lines with out opening the file /users/oracle > cat lnxdb-pts-454.xml|egrep "s_virtual|s_cluster|s_dlsnstatus" <cluster_port oa_var="s_clusterServicePort">9998</cluster_port> <host... (2 Replies)
Discussion started by: smarlaku
2 Replies

9. UNIX for Beginners Questions & Answers

Delete columns with a specific title XXX, where the position change in each file

Goodmorning, I know how to cut a string and a column, and how to find a word. I have a file with over 100 columns. All columns have a title in the first line. I have to delete all columns with the XXX title. I can't use cut -f because the position of XXX columns change in each file, and in... (14 Replies)
Discussion started by: echo manolis
14 Replies

10. Shell Programming and Scripting

awk to change specific string to new value if found in text file

I am trying to use awk to change a specific string in a field, if it is found, to another value. In the tab-delimited file the text in bold in $3 contains the string 23, which is always right before a ., if it is present. I am trying to change that string to X, keeping the formatting and the... (3 Replies)
Discussion started by: cmccabe
3 Replies
MIB2C.CONF(5)							     Net-SNMP							     MIB2C.CONF(5)

NAME
mib2c.conf -- How to write mib2c.conf files to do ANYTHING based on MIB input. SYNOPSIS
% cat > mib2c.test.conf << EOF @foreach $t table@ Starting table $t @foreach $c column@ echo $t has column $c which has a syntax of $c.syntax @end@ @end@ EOF % mib2c -c mib2c.test.conf internet DESCRIPTION
The mib2c.conf script language is a MIB-particular language designed to easily process MIB nodes in ways that you want. mib2c is a mis- nomer (for historical purposes), because you can produce anything (not just C code). Look in the Net-SNMP "local" directory for a bunch of example mib2c.*.conf files and behold the power before you. COMMANDS
All commands within mib2c.conf files are embraced by @ signs. Anything with an @ sign at the front and back of the line is generally sup- posed to be a mib2c specific command. These are detailed here: @open FILE@ writes generated output to FILE note that for file specifications, opening '-' will print to stdout. @append FILE@ appends the given FILE @close FILE@ closes the given FILE @push@ save the current outputs, then clear outputs. Use with @open@ and @pop@ to write to a new file without interfering with current out- puts. @pop@ pop up the process() stack one level. Use after a @push@ to return to the previous set of open files. @foreach $VAR scalar@ repeat iterate over code until @end@ setting $VAR to all known scalars @foreach $VAR table@ repeat iterate over code until @end@ setting $VAR to all known tables @foreach $VAR column@ repeat iterate over code until @end@ setting $VAR to all known columns within a given table. Obviously this must be called within a foreach-table clause. @foreach $VAR nonindex@ repeat iterate over code until @end@ setting $VAR to all known non-index columns within a given table. Obviously this must be called within a foreach-table clause. @foreach $VAR internalindex@ repeat iterate over code until @end@ setting $VAR to all known internal index columns within a given table. Obviously this must be called within a foreach-table clause. @foreach $VAR externalindex@ repeat iterate over code until @end@ setting $VAR to all known external index columns within a given table. Obviously this must be called within a foreach-table clause. @foreach $VAR index@ repeat iterate over code until @end@ setting $VAR to all known indexes within a given table. Obviously this must be called within a foreach-table clause. @foreach $VAR notifications@ repeat iterate over code until @end@ setting $VAR to all known notifications @foreach $VAR varbinds@ repeat iterate over code until @end@ setting $VAR to all known varbinds Obviously this must be called within a foreach-notifications clause. @foreach $LABEL, $VALUE enum@ repeat iterate over code until @end@ setting $LABEL and $VALUE to the label and values from the enum list. @foreach $RANGE_START, $RANGE_END range NODE@ repeat iterate over code until @end@ setting $RANGE_START and $RANGE_END to the legal accepted range set for a given mib NODE. @foreach $var stuff a b c d@ repeat iterate over values a, b, c, d as assigned generically (ie, the values are taken straight from the list with no mib-expan- sion, etc). @while expression@ repeat iterate over code until the expression is false @eval $VAR = expression@ evaluates expression and assigns the results to $VAR. This is not a full perl eval, but sort of a ""psuedo"" eval useful for simple expressions while keeping the same variable name space. See below for a full-blown export to perl. @perleval STUFF@ evaluates STUFF directly in perl. Note that all mib2c variables interpereted within .conf files are in $vars{NAME} and that a warn- ing will be printed if STUFF does not return 0. (adding a 'return 0;' at the end of STUFF is a workaround. @startperl@ @endperl@ treats everything between these tags as perl code, and evaluates it. @next@ restart foreach; should only be used inside a conditional. skips out of current conditional, then continues to skip to end for the current foreach clause. @if expression@ evaluates expression, and if expression is true processes contained part until appropriate @end@ is reached. If the expression is false, the next @elsif expression@ expression (if it exists) will be evaluated, until an expression is true. If no such expression exists and an @else@ clause is found, it will be evaluated. @ifconf file@ If the specified file can be found in the conf file search path, and if found processes contained part until an appropriate @end@ is found. As with a regular @if expression@, @elsif expression@ and @else@ can be used. @ifdir dir@ If the specified directory exists, process contained part until an appropriate @end@ is found. As with a regular @if expression@, @elsif expression@ and @else@ can be used. @define NAME@ @enddefine@ Memorizes ""stuff"" between the define and enddefine tags for later calling as NAME by @calldefine NAME@. @calldefine NAME@ Executes stuff previously memorized as NAME. @printf "expression" stuff1, stuff2, ...@ Like all the other printf's you know and love. @run FILE@ Sources the contents of FILE as a mib2c file, but does not affect current files opened. @include FILE@ Sources the contents of FILE as a mib2c file and appends its output to the current output. @prompt $var QUESTION@ Presents the user with QUESTION, expects a response and puts it in $var @print STUFF@ Prints stuff directly to the users screen (ie, not to where normal mib2c output goes) @quit@ Bail out (silently) @exit@ Bail out! VARIABLES
Variables in the mib2c language look very similar to perl variables, in that they start with a "$". They can be used for anything you want, but most typically they'll hold mib node names being processed by @foreach ...@ clauses. They also have a special properties when they are a mib node, such that adding special suffixes to them will allow them to be interpreted in some fashion. The easiest way to understand this is through an example. If the variable 'x' contained the word 'ifType' then some mag- ical things happen. In mib2c output, anytime $x is seen it is replaced with "ifType". Additional suffixes can be used to get other aspects of that mib node though. If $x.objectID is seen, it'll be replaced by the OID for ifType: ".1.3.6.1.2.1.2.2.1.3". Other suffixes that can appear after a dot are listed below. One last thing: you can use things like $vartext immediately ending in some other text, you can use {}s to get proper expansion of only part of the mib2c input. IE, $xtext will produce "$xtext", but ${x}text will produce "ifTypetext" instead. $var.uc all upper case version of $var $var.objectID dotted, fully-qualified, and numeric OID $var.commaoid comma separated numeric OID for array initialization $var.oidlength length of the oid $var.subid last number component of oid $var.module MIB name that the object comes from $var.parent contains the label of the parent node of $var. $var.isscalar returns 1 if var contains the name of a scalar $var.iscolumn returns 1 if var contains the name of a column $var.children returns 1 if var has children $var.perltype node's perl SYNTAX ($SNMP::MIB{node}{'syntax'}) $var.type node's ASN_XXX type (Net-SNMP specific #define) $var.decl C data type (char, u_long, ...) $var.readable 1 if an object is readable, 0 if not $var.settable 1 if an object is writable, 0 if not $var.creatable 1 if a column object can be created as part of a new row, 0 if not $var.noaccess 1 if not-accessible, 0 if not $var.accessible 1 if accessible, 0 if not $var.storagetype 1 if an object is a StorageType object, 0 if not $var.rowstatus 1 if an object is a RowStatus object, 0 if not 'settable', 'creatable', 'lastchange', 'storagetype' and 'rowstatus' can also be used with table variables to indicate whether it contains writable, creatable, LastChange, StorageType or RowStatus column objects $var.hasdefval returns 1 if var has a DEFVAL clause $var.defval node's DEFVAL $var.hashint returns 1 if var has a HINT clause $var.hint node's HINT $var.ranges returns 1 if var has a value range defined $var.enums returns 1 if var has enums defined for it. $var.access node's access type $var.status node's status $var.syntax node's syntax $var.reference node's reference $var.description node's description SEE ALSO
mib2c(1) VVERSIONINFO
28 Apr 2004 MIB2C.CONF(5)
All times are GMT -4. The time now is 04:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy