Sponsored Content
Top Forums Shell Programming and Scripting Scanning Line by Line and Replace Post 302558900 by filter on Sunday 25th of September 2011 10:52:23 PM
Old 09-25-2011
Scanning Line by Line and Replace

Hi Everyone,

I have a file which contains the autosys (job scheduler) JIL (Job Information Language) Information.
For Example:
Code:
/* ----------------- TS_QDB_DATA_MASK_RUN ----------------- */

insert_job: TS_QDB_DATA_MASK_RUN   job_type: c
command: ${DATA_BIN}/hrt_data_mask.sh
machine: TS_QDB_MACHINE
#owner: qc_dev
permission: gx,mx
date_conditions: 1
days_of_week: all
start_times: "4:07,5:07,6:07,7:07,8:07,9:07,10:07,11:07,12:07,13:07,14:07,15:07,16:07,17:07,18:07,19:07,20:07,21:07"
description: "TS_QDB_DATA_MASK_RUN for masking data in LFSS2"
term_run_time: 60
std_out_file: ${DATA_ROOT}/logs/TS_QDB_DATA_MASK_RUN.`date +%Y%m%d`.log
std_err_file: ${DATA_ROOT}/logs/TS_QDB_DATA_MASK_RUN_err.`date +%Y%m%d`.log
max_run_alarm: 60
alarm_if_fail: 1
profile: /home/.autosys_profile
timezone: US/Eastern


.....So on

In the above file, I need to replace the word "TS_QDB_" with "KB_OM_1876_" i.e. in the fields "Insert_job:", "std_out_file:, "std_err_file:".

So Basically I need to scan the file line by line and need to replace the word appropriately.

I have started writing a perl scrip for the same but facing the issue while replacing the word.

Code:
#!/usr/bin/perl

$file=$ARGV[0] ;
$old_name=$ARGV[1] ;
$new_name=$ARGV[2] ;

open(FILE,$file)|| die ("could not open file $file: $!");
open(OUT1,'>','goodfile');

my $line;
$line = $_;

while(<FILE>)
{
if ($newline =~ /insert_job:/) {
        $newline =~ s/$old_name/$new_name/g;
        print OF $newline ;
}

elsif < Checking for the other two conditions i.e. std_out , std_err >

else
  {
    print OF $newline ;
  }
}
close FILE;
close OUT1;

where the Arg[0] is the <Input file> , Arg[1] = TS_QDB_" & Arg[2] = "KB_OM_1876_"

Could someone please help me out with some thoughts.

I would really appreciate your thoughts.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed - Replace Line which contains the Pattern match with a new line

I need to replace the line containing "STAGE_DB" with the line "STAGE_DB $DB # database that contains the table being loaded ($workingDB)" Here $DB is passed during the runtime. How can I do this? Thanks, Kousikan (2 Replies)
Discussion started by: kousikan
2 Replies

2. Shell Programming and Scripting

Scanning columns for duplicates and printing in one line

Description of data: NC_002737.1 4 F1VI4M001A3IAU F1VI4M001A3IAU F1VI4M001A3IAU F1VI4M001A3IAU NC_006372.1 5 F1VI4M001BH0HY FF1VI4M001BH0HY F1VI4M001C0ZC5 F1VI4M001DOF2X F1VI4M001AYNTS Every field in every record is tab separated There can be "n" columns. Problem: What I want to... (4 Replies)
Discussion started by: Deep9000
4 Replies

3. Solaris

Line too long error Replace string with new line line character

I get a file which has all its content in a single row. The file contains xml data containing 3000 records, but all in a single row, making it difficult for Unix to Process the file. I decided to insert a new line character at all occurrences of a particular string in this file (say replacing... (4 Replies)
Discussion started by: ducati
4 Replies

4. Shell Programming and Scripting

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... (6 Replies)
Discussion started by: nithins007
6 Replies

5. 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

6. Shell Programming and Scripting

I need to know how to replace a line after a pattern match with an empty line using SED

Hi How Are you? I am doing fine! I need to go now? I will see you tomorrow! Basically I need to replace the entire line containing "doing" with a blank line: I need to the following output: Hi How Are you? I need to go now? I will see you tomorrow! Thanks in advance.... (1 Reply)
Discussion started by: sags007_99
1 Replies

7. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

8. Shell Programming and Scripting

Multiple line search, replace second line, using awk or sed

All, I appreciate any help you can offer here as this is well beyond my grasp of awk/sed... I have an input file similar to: &LOG &LOG Part: "@DB/TC10000021855/--F" &LOG &LOG &LOG Part: "@DB/TC10000021852/--F" &LOG Cloning_Action: RETAIN &LOG Part: "@DB/TCCP000010713/--A" &LOG &LOG... (5 Replies)
Discussion started by: KarmaPoliceT2
5 Replies

9. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

10. Shell Programming and Scripting

Replace values in script reading line by line using sed

Hi all, Let's say I have a script calling for the two variables PA_VALUE and PB_VALUE. for pa in PA_VALUE blah blah do for pb in PB_VALUE blah blah do I have a text file with two columns of values for PA and PB. 14.5 16.7 7.8 9.5 5.6 3.6 etc etc I would like to read this... (7 Replies)
Discussion started by: crimsonengineer
7 Replies
erl_parse(3erl) 					     Erlang Module Definition						   erl_parse(3erl)

NAME
erl_parse - The Erlang Parser DESCRIPTION
This module is the basic Erlang parser which converts tokens into the abstract form of either forms (i.e., top-level constructs), expres- sions, or terms. The Abstract Format is described in the ERTS User's Guide. Note that a token list must end with the dot token in order to be acceptable to the parse functions (see erl_scan(3erl) ). EXPORTS
parse_form(Tokens) -> {ok, AbsForm} | {error, ErrorInfo} Types Tokens = [Token] Token = {Tag,Line} | {Tag,Line,term()} Tag = atom() AbsForm = term() ErrorInfo = see section Error Information below. This function parses Tokens as if it were a form. It returns: {ok, AbsForm} : The parsing was successful. AbsForm is the abstract form of the parsed form. {error, ErrorInfo} : An error occurred. parse_exprs(Tokens) -> {ok, Expr_list} | {error, ErrorInfo} Types Tokens = [Token] Token = {Tag,Line} | {Tag,Line,term()} Tag = atom() Expr_list = [AbsExpr] AbsExpr = term() ErrorInfo = see section Error Information below. This function parses Tokens as if it were a list of expressions. It returns: {ok, Expr_list} : The parsing was successful. Expr_list is a list of the abstract forms of the parsed expressions. {error, ErrorInfo} : An error occurred. parse_term(Tokens) -> {ok, Term} | {error, ErrorInfo} Types Tokens = [Token] Token = {Tag,Line} | {Tag,Line,term()} Tag = atom() Term = term() ErrorInfo = see section Error Information below. This function parses Tokens as if it were a term. It returns: {ok, Term} : The parsing was successful. Term is the Erlang term corresponding to the token list. {error, ErrorInfo} : An error occurred. format_error(ErrorDescriptor) -> Chars Types ErrorDescriptor = errordesc() Chars = [char() | Chars] Uses an ErrorDescriptor and returns a string which describes the error. This function is usually called implicitly when an ErrorInfo structure is processed (see below). tokens(AbsTerm) -> Tokens tokens(AbsTerm, MoreTokens) -> Tokens Types Tokens = MoreTokens = [Token] Token = {Tag,Line} | {Tag,Line,term()} Tag = atom() AbsTerm = term() ErrorInfo = see section Error Information below. This function generates a list of tokens representing the abstract form AbsTerm of an expression. Optionally, it appends Moretokens . normalise(AbsTerm) -> Data Types AbsTerm = Data = term() Converts the abstract form AbsTerm of a term into a conventional Erlang data structure (i.e., the term itself). This is the inverse of abstract/1 . abstract(Data) -> AbsTerm Types Data = AbsTerm = term() Converts the Erlang data structure Data into an abstract form of type AbsTerm . This is the inverse of normalise/1 . ERROR INFORMATION
The ErrorInfo mentioned above is the standard ErrorInfo structure which is returned from all IO modules. It has the format: {ErrorLine, Module, ErrorDescriptor} A string which describes the error is obtained with the following call: Module:format_error(ErrorDescriptor) SEE ALSO
io(3erl) , erl_scan(3erl) , ERTS User's Guide Ericsson AB stdlib 1.17.3 erl_parse(3erl)
All times are GMT -4. The time now is 02:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy