Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replace "" for "/tmp/" when line begins with the word string

Status
Not open for further replies.

amdx64bt

Technical User
Mar 30, 2009
9
CH
I want to replace this "" for this "/tmp/" in all the files of a folder. But only in the lines that begin with the word string. (Please notice that the input has "" and the output has to "").
 
Hi

What I understood from your words :
Code:
awk '/^word/{sub(/""/,"\"/tmp/\"")}1' /input/file

[gray]# or[/gray]

awk '/^\w/{sub(/""/,"\"/tmp/\"")}1' /input/file
If none of them is what you want, please show us a sample input and the desired output.

Feherke.
 
#Input:
string texturename = ""; )
Ct = ( texturename != "" ) ?

#Output
string texturename = "/tmp/"; )
Ct = ( texturename != "" ) ?
 
Hi

Got it.
Code:
awk '$1=="string"{sub(/""/,"\"/tmp/\"")}1' /input/file

[gray]# or[/gray]

awk '$1~/^string/{sub(/""/,"\"/tmp/\"")}1' /input/file
The first will not replace the following lines, the second will replace them too :

[tt] string:whatever = "";
string="";
stringlist whatever = "";[/tt]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top