Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Search&Replace "Multi-line" text in multiple f

Status
Not open for further replies.

mask_layout

Member level 2
Member level 2
Joined
Apr 4, 2006
Messages
45
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Activity points
1,650
I am replacing a single line text with multiple line text. I will be doing this for about a hundred files and I think its crazy to work on it 1by1.

Im new to shell scripting in unix and cant get the following command to work on replacing single line to multiple lines.

Code:
#!/usr/local/bin/tcsh
foreach file (*.TECH)
   set newname=`basename $file .TECH`
   mv $file $newname"_DFM.TECH"
   end

foreach DFMfile (*_DFM.TECH)
  cat $DFMfile | perl -pi -e "s/OneLinerOldText/NewMultipleLineText/g;" >$DFMfile
end

This is my sample INPUT FILE
block "xxx"
{
line1 = 0
line2 = 0
OneLinerOldText = 0
line3
line4 }

NEW FILE I want to OUTPUT
block "xxx"
{
line1 = 0
line2 = 0
NewMultipleLine1
NewMultipleLine2
NewMultipleLine3
line3
line4 }

Can somebody help me to get this working please?
 

Re: Search&Replace "Multi-line" text in multip

In Unix shell, if you write in command line

Code:
cat FILE | echo >FILE

Then you would got an empty file. Because they clear the FILE first.

Therefore, just use a intermidiate file to prevent the mistake:

Code:
#!/usr/local/bin/tcsh
foreach file ( *.TECH )
        set newname=`basename $file .TECH`
        mv $file $newname"_DFM.TECH"
end

set ext=.ext

foreach DFMfile ( *_DFM.TECH )
        cat $DFMfile | perl -pi -e "s/OneLinerOldText/NewMultipleLineText/g;" >$DFMfile$ext
        mv $DFMfile$ext $DFMfile
end
 

Re: Search&Replace "Multi-line" text in multip

Hi wstu,

thanks for the reply.... ur script made it better... thanks thanks..

anyway, my real problem is that i cannot print in multiple lines... my output is always placed in a single line. I tried sed, grep and perl.... none works... or maybe i dont know the correct syntax...

im trying to use "\n" but it only prints as output.

's/oldonelinertext/new\nNew\nLiner\nText/g';

does not output

new
New
Liner
Text...
:cry:
[/b]
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top