Visit Our UNIX and Linux User Community


finding a block in a file and replace with another file block.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting finding a block in a file and replace with another file block.
# 1  
Old 09-28-2009
finding a block in a file and replace with another file block.

(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 last line is “WHERE testvalue is not null”. Through this way I can identify this block.

(2) Are all the blocks identical? If so, which block do you want replaced? The 1st, 2nd, 25th? Or all?

Ans: Not all block are identical only few of them are identical. The block which I want to replace is not present in this file (xyz_abc.sql). I want to find this identical block from xyz_abc.sql and then replace the block which is present in another file called repl_file.sql.

The xyz_abc.sql file contains 25 blocks. In xyz_abc.sql file I need to identify the following 5 lines block.

rem Subset Rows (&&tempName.*)
CREATE VIEW &&tempName.* AS
SELECT *
FROM &&tempName.*
WHERE testvalue is not null.

And then replace with following block which is present in repl_file.sql. This repl_file.sql contains only one block.

rem Subset Rows (&&tempName.*)
CREATE VIEW &&tempName.* AS
SELECT STUDYID STUDYID, DOMAIN DOMAIN, USUBJID USUBJID, ggg(y) ABSEQ,
ABGRPID ABGRPID, ABREFID ABREFID, ABSPID ABSPID, testvalue
testvalue, ABTEST ABTEST, ABCAT ABCAT, ABSCAT ABSCAT, ABPOS
ABPOS, ABOARES ABOARES, ABORRESU ABORRESU, ABNRIND ABNRIND,
ABSERESC ABSERESC, ABSTEESN ABSTEESN, ABSTRESU ABSTRESU,
ABSTAT ABSTAT, ABREBSND ABREBSND, ABXFN ABXFN, ABNAM ABNAM,
ABLOINC ABLOINC, ABMETHOD ABMETHOD, ABBLFL ABBLFL, ABDRVFL
ABDRVFL, ABEVAL ABEVAL, VISIT VISIT, VISITNUM VISITNUM,
VISITDY VISITDY, ABDTC ABDTC, ABDY ABDY, ABTPTNUM ABTPTNUM,
ABTPT ABTPT, ABELTM ABELTM, ABTPTFEF ABTPTFEF, X1 X1, X2 X2,
X3 X3, X4 X4, X5 X5, X6 X6, X7 X7, X8 X8, X9 X9, X10 X10, X11
X11, X12 X12, X13 X13, X14 X14, X15 X15, X16 X16, X17 X17, X18
X18, X19 X19, X20 X20, X21 X21, X22 X22, X23 X23, X24 X24, X25
X25, X26 X26, X27 X27, X28 X28, X29 X29, X30 X30
FROM &&tempName.*
WHERE testvalue is not null

The 1st line and last of this block is unique. thru this way can identify.

Not all the blocks are identical only few of them is identical. The block which i want replace is not present in xyz_abc.sql.

can we do this way.

my target file should be removed the identical block from xyz_abc.sql file and replace with repl_file.sql file block.

Please suggest.

Thanks in advance

---------- Post updated at 11:37 PM ---------- Previous update was at 11:59 AM ----------

Please suggest some code

Thanks in Advance
# 2  
Old 09-28-2009
Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.

Previous Thread | Next Thread
Test Your Knowledge in Computers #616
Difficulty: Medium
There is no separate char data type in Python.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get values block by block in same file

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)
Discussion started by: garvit184
17 Replies

2. UNIX for Advanced & Expert Users

Challenges in finding and copying the block

Hi, I have a below challenging task where iam unable to find the block and copy the same into a file. I tried my luck,howver iam unable to reach the first and second step..Can anyone help me with a clue or with the commands so that i can give a try. 1. search the <number>9966993366</number>... (2 Replies)
Discussion started by: cskumar
2 Replies

3. Shell Programming and Scripting

Printing a block of lines from a file, if that block does not contain two patterns using sed

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)
Discussion started by: Kesavan
8 Replies

4. UNIX for Advanced & Expert Users

Move a block of lines to file if string found in the block.

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)
Discussion started by: grep_me
7 Replies

5. Shell Programming and Scripting

using sed/awk to replace a block of text in a file?

My apologies if this has been answered in a previous post. I've been doing a lot of searching, but I haven't been able to find what I was looking for. Specifically, I am wondering if I can utilize sed and/or awk to locate two strings in a file, and replace everything between those two strings... (12 Replies)
Discussion started by: kiddsupreme
12 Replies

6. SuSE

finding and removing block of identical strings

i have a problem in finding block of identical strings...i solved the problem in finding consecutive identical words and now i want to expand the code in order to find and remove consecutive identical block of strings... for example the awk code removing consecutive identical word is:... (2 Replies)
Discussion started by: cocostaec
2 Replies

7. Shell Programming and Scripting

Script to put block comment after finding regex in xml file

hi, i need my bash script to find regex in xml file.. and comment 2 lines before and after the line that contains regex.. can't use # needs to be <!-- at the beginning and --> and the end of the comment. so eg.. first block <filter> <filter-name>MyRegEx</filter-name> ... (11 Replies)
Discussion started by: Poki
11 Replies

8. Shell Programming and Scripting

replace block of text with content of another file

Hello, file1: not to be changed not to be changed <start> old stuff old stuff old stuff <end> not to be changed not to be changed file2: new text new text desired output: (3 Replies)
Discussion started by: ripat
3 Replies

9. Shell Programming and Scripting

Delete block of text in one file based on list in another file

Hi all I currently use the following in shell. #!/bin/sh while read LINE do perl -i -ne "$/ = ''; print if !m'Using archive: ${LINE}'ms;" "datafile" done < "listfile" NOTE the single quote delimiters in the expression. It's highly likely the 'LINE' may very well have characters in it... (3 Replies)
Discussion started by: Festus Hagen
3 Replies

10. Shell Programming and Scripting

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 "... (5 Replies)
Discussion started by: aoussenko
5 Replies

Featured Tech Videos