Gawk - Text replace - need help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Gawk - Text replace - need help
# 8  
Old 02-13-2013
Quote:
Originally Posted by Baefisch
always invalid char ''' in expression?
whats my mistake?

run gawk -f test.awk test.txt
huh?
Who are you asking and what are you asking?
# 9  
Old 02-13-2013
everybody... Smilie

i type in a cmd
gawk -f test.awk test.txt

test.awk
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

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

---------- Post updated at 09:53 AM ---------- Previous update was at 09:51 AM ----------

and this is the output:
invalid char ''' in expression


sorry for my stupid questions..

Last edited by Baefisch; 02-13-2013 at 10:56 AM.. Reason: code tags, please!
# 10  
Old 02-13-2013
Code:
gawk -F. -f test.awk OFS=. myFile

test.awk:
Code:
   substr($3,1,index($3,"=")-1)=="mainclass" {print "#" $0;$NF="xyz"}
   substr($3,1,index($3,".")-1)=="classpath" {$(NF-1)="*"}    
   1

# 11  
Old 02-13-2013
ahh.. ok. but if i try this the changed code is only shown in the cmd, but not in the text file.

Smilie
# 12  
Old 02-13-2013
Quote:
Originally Posted by Baefisch
ahh.. ok. but if i try this the changed code is only shown in the cmd, but not in the text file.

Smilie
gawk -F. -f test.awk OFS=. myFile > myNewFile
# 13  
Old 02-14-2013
thanks you very much.
I am not worthy

---------- Post updated 02-14-13 at 05:24 AM ---------- Previous update was 02-13-13 at 10:05 AM ----------

sorry, me again.

second one doesn´t work.
Can you explaine me this?


this is what i get:

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

---------- Post updated at 06:29 AM ---------- Previous update was at 05:24 AM ----------

HELP please, i am Smilie

---------- Post updated at 07:03 AM ---------- Previous update was at 06:29 AM ----------

its ok.. it works now°! Smilie
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