Re: search for charater "="



On Monday 5 May 2008 09:31, Nezhate wrote:

Hi there
I'm using awk to search the character equal "=" and replace it with
space character " " in file1. The result is redirected to another
file2.

----------------file1-------------------
field1="data1"after there is some data...
field2="data2"after there is some data...
field3="data3"after there is some data...
field4="data4"after there is some data...
-----------------end_file1---------------------

I used this
awk 's/=/ ' file1 >> file2

but I get this error

awk: s/=/TEST
awk: ^ unterminated regexp


I want to have the next file
----------------file2-------------------
field1 "data1"after there is some data...
field2 "data2"after there is some data...
field3 "data3"after there is some data...
field4 "data4"after there is some data...
-----------------end_file2---------------------

how to indicate that I'm searching for character and not for an
unterminated regular expression?
Thanks for your help.

I think you are a bit confused here. You are using what looks like sed
syntax (although incorrect) as a command to awk. So, either do

sed 's/=/ /' file1

(this replaces only the first = in each line; if you want to replace all =,
then use
sed 's/=/ /g' file1)

or, if you want to use awk, then do

awk 'sub(/=/," ")+1' file1

(again, this replaces only the first = in each line; if you want to replace
all =, then do
awk 'gsub(/=/," ")+1' file1)

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
.



Relevant Pages

  • Re: Less greedy pattern match
    ... starts with the line number (ran each command 3 times, ... other assorted tests on 1-million lines file (GNU awk). ... All the commands are tested with bash and GNU tools, ... nonstandard features. ...
    (comp.lang.awk)
  • Re: scan the files data have Chr value > "~"
    ... # on print first 7 lines on screen ... awk ' BEGIN { ... But 'tot' has been faithfully counting how many lines contain at least one such character. ...
    (comp.lang.awk)
  • Re: Using a regexp as field separator does not work!
    ... "field separator" if the regex '| *' is used as FS. ... alternation is used? ... just like an FS of a single blank character is a special case. ... could be optimized and awk doesn't try to analyze and warn you about any of them ...
    (comp.lang.awk)
  • Re: Using a regexp as field separator does not work!
    ... "field separator" if the regex '| *' is used as FS. ... alternation is used? ... just like an FS of a single blank character is a special case. ... could be optimized and awk doesn't try to analyze and warn you about any of them ...
    (comp.lang.awk)
  • Re: awk print system date and time
    ... I am using awk for reformat vmstat data. ... What makes you think your command takes more than 1 second to run? ... nonstandard features. ...
    (comp.unix.shell)