Gawk - Text replace - need help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Gawk - Text replace - need help
# 1  
Old 02-13-2013
Gawk - Text replace - need help

Hello, i am a working student and have to build a patch setup.
I have to replace 2 lines in a .txt file. Can someone help me please.

Now:
Code:
wrapper.java.mainclass=org.tanukisoftware.wrapper. WrapperSimpleApp
wrapper.java.classpath.2=../../jdk/lib/tools.jar

replace with:
Code:
#wrapper.java.mainclass=org.tanukisoftware.wrapper .WrapperSimpleApp
wrapper.java.mainclass=org.tanukisoftware.wrapper. xyz
wrapper.java.classpath.2=../../jdk/lib/*.jar

I´ve tested some examples from the internet.
I do not understand the awk or any other programming language.
Can somebody help me please?

By the way. Sorry for my bad englisch.

THX!!! Smilie

Last edited by joeyg; 02-13-2013 at 10:27 AM.. Reason: Please wrap commands and data with CodeTags
# 2  
Old 02-13-2013
So, are your trying to change the following two?

WrapperSimpleApp to xyz
tools.jar to *.jar
# 3  
Old 02-13-2013
Code:
awk -F'[.=]' '$3=="mainclass" {print "#" $0;$NF="xyz"}1' myFile

# 4  
Old 02-13-2013
Code:
awk ' /^wrapper\.java\.mainclass/ {
        v = $0;
        print "#"$0;
        sub(/\.[a-zA-Z0-9]*$/,".xyz",v);
        print v;
} /^wrapper\.java\.classpath\.2/ {
        sub(/\/[a-zA-Z0-9]*$/,"*.jar",$0);
        print;
} ' file

# 5  
Old 02-13-2013
yes change the two
Code:
wrapper.java.mainclass=org.tanukisoftware.wrapper. WrapperSimpleApp
wrapper.java.classpath.2=../../jdk/lib/tools.jar

and paste one line with and # for a comment.


So that it looks like:
Code:
#wrapper.java.mainclass=org.tanukisoftware.wrapper .WrapperSimpleApp
wrapper.java.mainclass=org.tanukisoftware.wrapper. xyz
wrapper.java.classpath.2=../../jdk/lib/*.jar

Thank you very much
# 6  
Old 02-13-2013
or rather:
Code:
awk -F. '
   substr($3,1,index($3,"=")-1)=="mainclass" {print "#" $0;$NF="xyz"}
   substr($3,1,index($3,".")-1)=="classpath" {$(NF-1)="*"}
   1
' OFS=. myFile

# 7  
Old 02-13-2013
always invalid char ''' in expression?
whats my mistake?

cmd
gawk -f test.awk test.txt
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

gawk script to search and replace text in a flat file

Hi I am new to unix and newbie to this forum. I need help in writing a gawk script that search and replace particular text in a flat file. Input file text : ZIDE_CONTROL000 100000000003869920900000300000001ISYNC 000002225489 0000000002232122 20120321 16:40:53 ZIDE_RECORD000... (5 Replies)
Discussion started by: gkausmel
5 Replies

2. UNIX for Dummies Questions & Answers

replace text

Hello I'm trying to replace in a text file the chain by 107,192,196,207 107.207 but I can not I tried the following cat translator_swift.properties.in_modif | sed 's/107\,207/107,192,196,207/g' > translator_swift.properties.in_modif Can you help me? thanks (8 Replies)
Discussion started by: nonanov
8 Replies

3. Shell Programming and Scripting

Find and add/replace text in text files

Hi. I would like to have experts help on below action. I have text files in which page nubmers exists in form like PAGE : 1 PAGE : 2 PAGE : 3 and so on there is other text too. I would like to know is it possible to check the last occurance of Page... (6 Replies)
Discussion started by: lodhi1978
6 Replies

4. Shell Programming and Scripting

Text manipulation with gawk

Hi all, I have a very long document in the following format: jkjlk cc1 dd1 cc2 dd2 cc3 dd3 and so on ... The expected result should be a table aa1 bb1;cc1;dd1 aa2 bb2;cc2;dd2 (18 Replies)
Discussion started by: Robert_M
18 Replies

5. UNIX for Dummies Questions & Answers

JOINING MULTIPLE LINES IN A TEXT FILE USING GAWK

sir... am having a data file of customer master., containing some important fields as a set one line after another., what i want is to have one set of these fields(rows) one after another in line.........then the second set... and so on... till the last set completed. I WANT THE DATA... (0 Replies)
Discussion started by: KANNI786
0 Replies

6. UNIX for Dummies Questions & Answers

Joining lines of a text file using GAWK

sir... am having a data file of customer master., containing some important fields as a set one line after another., what i want is to have one set of these fields(rows) one after another in line.........then the second set... and so on... till the last set completed. ... (0 Replies)
Discussion started by: KANNI786
0 Replies

7. Shell Programming and Scripting

How to replace text in a file with text entered

I am trying to write a shell script that will allow the typing of a value, then using that value to replace data in a text file. I suspect I need sed. The format of the file is: Variable1:Value1 Variable2:Value2 The interaction would be something like: Shell Prompt: "Please enter the... (9 Replies)
Discussion started by: cleanden
9 Replies

8. Shell Programming and Scripting

find text but replace a text beside it

I have an html file that looks like this (this is just a part of the html file): <td colspan="3" rowspan="1" style="text-align: center; background-color: rgb(<!-- IDENTIFIER1 -->51, 255, 51);"><small><!-- IDENTIFIER2 -->UP</small></td> This is to automatically update the status of the... (4 Replies)
Discussion started by: The One
4 Replies

9. UNIX for Advanced & Expert Users

Replace the text between two lines with different text

I have a file which contains the following data. Parameters "CParameters" BEGIN DSSUBRECORD Name "TgtDB" Prompt "TgtDB" Default "edwdev" ParamType "0" ParamLength "0" ParamScale "0" END DSSUBRECORD MetaBag... (6 Replies)
Discussion started by: ukatru
6 Replies

10. UNIX for Dummies Questions & Answers

search and replace a specific text in text file?

I have a text file with following content (3 lines) filename : output.txt first line:12/12/2008 second line:12/12/2008 third line:Y I would like to know how we can replace 'Y' with 'N' in the 3rd line keeping 1st and 2nd lines same as what it was before. I tried using cat output.txt... (4 Replies)
Discussion started by: santosham
4 Replies
Login or Register to Ask a Question