Sponsored Content
Top Forums Shell Programming and Scripting modify a file by inserting a conditional values Post 302596254 by balajesuri on Tuesday 7th of February 2012 03:53:02 AM
Old 02-07-2012
Code:
#! /usr/bin/perl -w
use strict;

my (@x, @y, $l1, $l2);

open I, "< inputfile";
for (<I>) {
    if (/^CCCC/) {
        print;
        ($l1, $l2) = ("   0", 1500);
    }
    if (/^DDDD/) {
        @x = split /\s+/;
        print shift @x , " " x 17;
        unshift (@x, $l1, $l2);
        if (@x > 10) { $l2 = pop @x; $l1 = pop @x; }
        print "@x\n";
    }
}
close I;

Code:
$ ./test.pl
CCCC                 1204     215764.85   9405410.40               1189
DDDD                    0 1500 4498 1503 4617 1507 4723 1517 4829 1528
DDDD                 4996 1540 5199 1556 5278 1567 5529 1603 5674 1614
DDDD                 6076 1915 6605 2371 7004 2779
CCCC                 1284     216035.45   9405830.95               1216
DDDD                    0 1500 4498 1503 4626 1505 4720 1515 4832 1529
DDDD                 4962 1537 5270 1569 5597 1596 5671 1607 5828 1694
DDDD                 6115 1933 6392 2165 7004 2810

1. Please don't bump posts.

2. I see that in many posts, you just don't bother to comment or thank on the solutions provided by members.
https://www.unix.com/shell-programmin...ent-files.html
https://www.unix.com/shell-programmin...ent-files.html
https://www.unix.com/shell-programmin...ern-found.html

3. You might want to read this post:
Flag that marks user so you can avoid them

Last edited by balajesuri; 02-07-2012 at 05:06 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Inserting Values From A File Into A Table

Guys, I want to insert some values from a log file into a temporary table. the values in the log file looks like this SV_NAME CC_NAME CP_DISP_RUN_STATE ------- ------------------- ----------------- sble01 ALLTEL WorkMon24Hrs Running I want to enter the... (2 Replies)
Discussion started by: ragha81
2 Replies

2. Shell Programming and Scripting

help in inserting values in date format

how to assign values in this date format a=`date +"%H%M%S"` how to give value of H=22,here in this format so that i can grep 22nd hour.Below is the script -------------------------------------------------------------------------- a=`date +"%H%M%S"` for i in *.log do cat $i | grep $a... (3 Replies)
Discussion started by: ali560045
3 Replies

3. Shell Programming and Scripting

conditional Testing numeric and text values problems

hi, when i type in a value higher than 20 it will show me the validation but if i put a negative figure it just goes goes blank where i just keep typing and nothing happens so i had to control c to exit out the process, can someone help me please. clear read -p "please enter... (2 Replies)
Discussion started by: bassmasta1
2 Replies

4. Shell Programming and Scripting

Perform Operations on One File Conditional on Data in Another File

Hello all, I am looking for a solution to the following problem. Perl or python solutions also welcome. Given this input: And this input: I want to get this output. The rule being that if the number in the first file is < 0.9, then the corresponding two columns on... (2 Replies)
Discussion started by: hydrabane
2 Replies

5. Shell Programming and Scripting

Inserting variable values in filename

Hi All, I have a directory containing multiple files. and also a txt file which contains the list of all filenames and certain values. I want to read the text file line by line and if its 2nd column is matched with the filename in directory, then it must insert the values in 7th column to... (14 Replies)
Discussion started by: CAch
14 Replies

6. Shell Programming and Scripting

Problem in inserting values of variable of shell

hi all, i have one shell script like this #!/bin/bash -xv ENV_NAME=`cat $IB_HOME_DIR/cfg/ibProfile.sh | grep "RDM_CONN" | cut -f 2 -d "@"` CURRENT_DIR=`pwd`; string=$IB_HOME_DIR string1="$string/FRGFOLDER/input" #sed "s/string3/$string1" frg_event_src.sql > modifiedinsert.sql sqlplus... (2 Replies)
Discussion started by: ramsavi
2 Replies

7. Shell Programming and Scripting

Modify existing values in a file

Hi, I am trying to write a shell script which will modify existing values and take backup of old values. file trying to modify is : /etc/sysctl.conf script name: modify.sh execute ./modify.sh enter ref no: 123 add below values in file sysctl.cnf kernel.shmall = 4194304 ... (7 Replies)
Discussion started by: darling
7 Replies

8. Shell Programming and Scripting

Pattern search and modify the values

I have one file and the file may contain 500 to 15,000 records. I need to search pattern ^F509= and then increment the corresponding value by one and print the entire line. Please note that Its not a fixed length file. Can anyone please help? ex: ^F509=204656 ^F509=204656 ... (6 Replies)
Discussion started by: vinus
6 Replies

9. Shell Programming and Scripting

Inserting values into database from an excel

Hi, I have a requirement where I have an excel sheet with the below values COL1 COL2 COL3 Germany URGENT NORMAL I want to cut the values of this excel in such a way that I get the values and pass it to an insert statement update tbfin set... (2 Replies)
Discussion started by: venkidhadha
2 Replies

10. Shell Programming and Scripting

Inserting values to database

hi , I'm new to Unix shell scripting. I need help to insert read csv which has two columns -emp no and logged date. csv file is a large file so i want to keep the insertion query in a separate .sql file. csv file looks this: empno | loggeddate ___________________ 5666 ,... (5 Replies)
Discussion started by: preema
5 Replies
PMWEBAPI(3)						     Library Functions Manual						       PMWEBAPI(3)

NAME
PMWEBAPI - introduction to the Performance Metrics Web Application Programming Interface OVERVIEW
The PMWEBAPI interface is a binding of a subset of the PMAPI to the web. It uses HTTP as transport, REST as organizational style for request/parameter encoding (the GET and POST methods are interchangeable), and JSON as response encoding. A context identifier is used as a persistent way to refer to PMAPI contexts across related web requests. These context identifiers expire after a configurable period of disuse. Errors generally result in HTTP-level error responses. CONTEXT CREATION
: pmNewContext To create a new web context identifier, a web client invokes: /pmapi/context?local=ANYTHING Creates a PM_CONTEXT_LOCAL PMAPI context. /pmapi/context?hostname=STRING /pmapi/context?hostspec=STRING Creates a PM_CONTEXT_HOST PMAPI context with the given host name and/or extended specification. If the host specification contains a userid/password combination, then the corresponding pmapi context operations will require HTTP Basic authentication credentials with matching userid/password. /pmapi/context?archivefile=ARCHIVE Creates a PM_CONTEXT_ARCHIVE PMAPI context with the given file name. In addition, the web client may add the parameter &polltimeout=MMMM for a maximum interval (in seconds) between expected accesses to the given context. This value is limited by pmwebd configuration, and is a courtesy to allow pmwebd to free up memory earlier in case of sud- den web application shutdown. If successful, the response from these requests is a JSON document of the form: { "context" : NNNNN } The number (a 32-bit unsigned decimal) is then used in all later operations. PMAPI OPERATIONS
The general form of the requests is as follows: /pmapi/NNNNN/OPERATION where /pmapi is the fixed prefix for all PMWEBAPI operations, NNNNN is a PMWEBAPI context number returned from a context-creation call, or assigned permanently at pmwebd startup, and OPERATION?PARAM1=VALUE2&PARAM2=VALUE2 identifies the operation and its URL-encoded parameters. Some parameters may be optional. METRIC METADATA: pmLookupName, pmLookupDesc, pmTraversePMNS_r The general form of the requests is as follows: /pmapi/NNNNN/_metric Traverse the entire PMNS. /pmapi/NNNNN/_metric?prefix=NAME Traverse the subtree of PMNS with the prefix NAME. The response is a JSON document that provides the metric metadata as an array. For example: { "metrics": [ { "name":"foo.bar", "pmID":PPPP, "indom":DDDD, "type":"32", "sem":"instant", "units":"MHz", "text-oneline":"foo bar", "text-help":"blah blah blah" }, { "name":"foo.bar2", ... } ... ] } Most of the fields are self-explanatory. PPPP the PMID DDDD the instance domain type from pmTypeStr units from pmUnitsStr sem an abbreviation of the metric semantic: PM_SEM_COUNTER "counter" PM_SEM_INSTANT "instant" PM_SEM_DISCRETE "discrete" METRIC VALUE: pmFetch The general form of the requests is as follows: /pmapi/NNNNN/_fetch?names=NAME1,NAME2 Fetch current values for given named metrics. /pmapi/NNNNN/_fetch?pmids=PPPP1,PPPP2 Fetch current values for given PMIDs. The response is a JSON document that provides the values for all requested metrics, for all their instances. { "timestamp": { "s":SEC, "us":USEC }, "values": [ { "pmid":PPPP1, "name":"NAME1", "instances:" [ { "instance":IIII1, "value":VALUE1 } { "instance":IIII2, "value":VALUE2 } ... ] }, { "pmid":PPPP2, "name":"NAME2", ... } ... ] } Most of the fields are self-explanatory. Numeric metric types are represented as JSON integer or floating-point values. Strings are passed verbatim, except that non-ASCII values are replaced with a Unicode 0xFFFD REPLACEMENT CHARACTER code. Event type metrics are not currently supported. INSTANCE DOMAINS METADATA: pmGetInDom, pmNameInDom, pmLookupInDom The general form of the requests is as follows: /pmapi/NNNN/_indom?indom=DDDD List instances of the given instance domain. /pmapi/NNNN/_indom?name=NAME List instances of the instance domain belonging to the named metric. In addition, either query may be suffixed with: &instance=IIII,JJJJ Restrict listings to given instance code numbers. &iname=INAME1,INAME2 Restrict listings to given instance names. The response is a JSON document that provides the metric metadata as an array. For example: { "indom":DDDD, "instances": [ { "instance":IIII, "name":"INAME" } ... ] } INSTANCE PROFILE: pmAddProfile, pmDelProfile /pmapi/NNNN/_profile_reset? These are not currently supported. /pmapi/NNNN/_profile_reset?indom=DDDD These are not currently supported. /pmapi/NNNN/_profile_add?indom=DDDD&instance=IIII,JJJJ These are not currently supported. /pmapi/NNNN/_profile_add?indom=DDDD&iname=IIII,JJJJ These are not currently supported. /pmapi/NNNN/_profile_del?indom=DDDD&instance=JJJJ These are not currently supported. /pmapi/NNNN/_profile_del?indom=DDDD&iname=INAME1,INAME2 These are not currently supported. DERIVED METRICS: pmRegisterDerived /pmapi/NNNNN/_derive?name=NAME&expr=EXPRESSION These are not currently supported. CONTEXT COPY: pmDupContext /pmapi/NNNNN/copy These are not currently supported. CONTEXT CLOSE: pmDestroyContext /pmapi/NNNNN/destroy This is not likely to be supported, as it is destructive and would offer a tempting target to brute-force attackers. Instead, the pmwebd timeout is used to automatically free unused contexts. SEE ALSO
PCPIntro(1), PCPIntro(3), pmwebd(3), and PMAPI(3) Performance Co-Pilot PCP PMWEBAPI(3)
All times are GMT -4. The time now is 01:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy