help-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem with GAWK/gsub when substitute new lines


From: Rita Shen
Subject: Re: problem with GAWK/gsub when substitute new lines
Date: Mon, 22 Jun 2009 11:01:07 +1000

Hi,

On Sat, Jun 20, 2009 at 5:13 PM, Ralf Wildenhues <address@hidden> wrote:
Hello Rita,

please don't top-post (put your answer above the text you reply to),
thank you.

* Rita Shen wrote on Fri, Jun 19, 2009 at 02:29:05AM CEST:
> I tried the command:
>
> awk 'BEGIN { RS="\&"};{
>     gsub(/\[[\n]+\]/, "");print $0}' gawk_test > gawk_modi
>
> But the content in gawk_modi is still the same as the gawk_test:
>
> <"Reports" [
>
>
>
> ]>

Hmm, that's weird, because for me, the above works.  However, I do get a
warning from awk:
 awk: warning: escape sequence `\&' treated as plain `&'

> By the way, what's the difference between RS and FS?

RS is the record separator, while FS is the field separator.  Records
are commonly lines, while fields are commonly words in a line, at least
that's how I interpret them.  Since you can change RS, FS, as well as
ORS and OFS (the corresponding output separators), they can of course
delimit different chunks of text.  But the general idea is that a file
is composed of zero or more records, and a record composed of zero or
more fields.

The gawk manual is pretty good about this stuff:
<http://www.gnu.org/software/gawk/manual/>

Hope that helps.

Cheers,
Ralf

In case that someone may be encountering similar problems. Finally this problem was resolved after adding carriage return in the command:
 awk 'BEGIN {RS="&"};{gsub(/[\r]*[\n]*/, "");print $0}' gawk_test > gawk_modi

Cheers,
Rita


reply via email to

[Prev in Thread] Current Thread [Next in Thread]