Portable and efficient way to add text after pattern
Shell: sh/bash
OS: Linux (all unix flavors)
Suppose i have a variable with this content:
I want to add this text to a file/script, only under the following conditions:
1. First, scan the file/script and verify that the first 2 lines of the ArgZ variable dont already exist in it. Meaning, make sure the exact patterns of "^import os$" and "^import sys$" aren't anywhere in the script. If they are, remove them.
2. Add the content of ArgZ and ArgZB only after the last line in the file/script that begins with an "import".
3. If there are no lines in the file/script that has an import, add the content of ArgZ and ArgZB to the top of the file/script right under the "#\!" line.
4. If a "#!" line does not exist, simply add the content of ArgZ and ArgZB to the top of the file/script.
So for example, if i have a file/script like the below:
the code i'm looking for should make the output look like this:
or like this:
what i was doing was greatly inefficient:
There's no logic here and im just adding the content to the beginning of the file/script. I want some logic applied to this.
In the awk I am trying to add :p.=? to the end of each $9 that matches the pattern NM_. The below executes andis close but I can not seem to figure out why the :p.=? repeats in the split as in the green in the current output. I have added comments as well. Thank you :).
file
... (4 Replies)
I have one array SPLNO with approx 10k numbers.Now i want to search the subscriber number from MDN.TXT file (containing approx 1.5 lac record)from the array.if subscriber number found in array it will perform below operation.my issue is that it's taking more time because for one number it's search... (6 Replies)
I have a list of files defined in a single file , one on each line.(No.of files may wary each time)
eg. content of ETL_LOOKUP.dat
/data/project/randomname
/data/project/ramname
/data/project/raname
/data/project/radomname
/data/project/raame
/data/project/andomname
size of these... (5 Replies)
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)
Hi,
I am trying to populate an array with data from a text file. I have a working method using awk but it is too slow and inefficent. See below.
The text file has 70,000 lines. As awk is a line editor it reads each line of the file until it gets to the required line and then processes it.... (3 Replies)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
Write a template main.c file via shell script to make it easier for yourself later.
The issue here isn't writing... (2 Replies)
This is my first post, please be nice. I have tried to google and read different tutorials.
The task at hand is:
Input file input.txt (example)
abc123defhij-E-1234jslo
456ujs-W-abXjklp
From this file the task is to grep the -E- and -W- strings that are unique and write a new file... (5 Replies)
Hi All,
The file has the following.
=========start of file===
This is a file containing employee info
START
name john
id 123
date 12/1/09
END
START
name sam
id 4234
date 12/1/08 resigned
END (9 Replies)
Hello,
I would like to add the line TIMEZONE="CET" if the pattern TIMEZONE is not found between the range <JOB and JOB> :
Example:
Src file:
<!DOCTYPE DEFTABLE SYSTEM "deftable.dtd">
<DEFTABLE >
<JOB
TASKTYPE="Job"
TIMEFROM="0030"
TIMEZONE="CET"
</JOB>
<JOB... (5 Replies)