how to append a block of statements after another block in the file
Hi
I need to append the following block of statements in the middle of the file: #
openpipe tsdbdwn2
set -x
exec >> /tmp/tsdbdwn2.fifo 2>&1
#
This needs to be appended right after another block of statements: if test $# -eq 0 ;then
echo "Safety check - do you really wish to run" $0 " on " `hostname` "?"
read safety
case $safety in
y|yes|Y|YES|Yes ) ;;
* ) echo $0: aborting ; exit 1 ;;
esac
fi
Is there an awk/sed commands which will allow me to do that, since I heed to update multiple files. Thanks a lot for any help.
How to insert a block of statements within a set of files
The smart answer is "no there is no easy way to do this. Edit the files yourself".
However, I took it as a challenge and came up with a solution, such as it is.
It will insert the new code multiple times, if necessary.
It's possible to get the wrong result if there is a lot of duplicate code in the file
and the lines follow each other with no breaks of any kind.
This is unlikely.
First, you need a file with the lines you want to insert .
newcode file:
#
You need a file containing the block of code which needs to be followed by the new code .
codepattern file:
And you need this script which finds sequences of matches against the code patterns
and generates sed commands to insert the new code wherever it is needed.
The output is a set of sed commands, which you can put in a file as a script,
or just pipe to "sh -x " to see them run.
i'll present my solution, too, but just cause it's an interesting paradigm
that can be modified to do almost anything.
Indeed - I like this a lot.
This is an excellent approach if the files to be edited have a unique and easily found
insertion point and it is safe to stuff in the change.
I need to search for a block with the starting pattern say
"tabId": "table_1", and ending pattern say "]"
and then add a few lines before "]"
"block1":"block_111"
"tabId": "table_1",
"title":"My title"
.....
....
}]
how do I achieve it using awk and sed.
Thanks,
Lakshmi (3 Replies)
I have a file say "SAMPLE.txt" with following content,
P1
10,9:6/123456
P2
blah blah
P1
10,9:5/98765
P2
blah
blah
P1
blah blah
P2
I want a output file say "RESULT.txt" as,
Value1:123456
Value2:98765
Value3:NULL (17 Replies)
Hi,
I have one array created and some values are there in ksh. I want to append some other values to it based on some condition in if statement.
#!/bin/ksh
echo "---------------------------------------------------"
set -A ipaddr_arr $(egrep -v '^#|^::|^$' /etc/hosts |awk '{print $1}'... (2 Replies)
Hi, I posted in another section, but no reply yet.
I have an ini file with sections denoted as follows (for example)
blah=blah
blee=blee
bloo=bloo
blur=blur
blaa=blaa
I have ksh script that needs to append a line ${line} to the end of section ${section}
I saw this... (7 Replies)
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)
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)
Hei buddies,
Need ur help once again.
I have a file which has bunch of lines which starts from a fixed pattern and ends with another fixed pattern.
I want to make use of these fixed starting and ending patterns to select the bunch, one at a time.
The input file is as follows.
Hi welcome... (12 Replies)
I was reading a book on UNIX internals "The design of the UNIX Operating system." There are two memory structures that are confusing me:
1) Buffer cache
2) Inode cache
My questions are
1) Does a process get both buffer cache and Indoe cache allocated when it opens/creates a file?
2) if no,... (1 Reply)
(1) Yes but how is this block different from the other 24? You will need this information in order to identify and replace this block correctly (out of the 25).
Ans: The 1st line and last line of this block are unique from other block.
The 1st line is “rem Subset Rows (&&tempName.*) and
The... (1 Reply)
Hi,
I need to convert the following file into DB insert statements.
$ cat input.txt
START
name=john
id=123
date=12/1/09
END
START
name=sam
id=4234
status=resigned
date=12/1/08
END (2 Replies)