f

#### Diff between '{..}' and {'..'}

Hi,

Could anyone tell me the difference between

......| awk '{.......}'

AND

......| awk {'......'}

And also when(in what situation) these are used?
Anil.


 0
anilby (27)
1/13/2005 6:37:14 AM
comp.lang.awk 3450 articles. 0 followers.

4 Replies
1532 Views

Similar Articles

[PageSpeed] 41

2005-01-12, 22:37(-08), Anil:
> Hi,
>
> Could anyone tell me the difference between
>
> .....| awk '{.......}'
>
> AND
>
> .....| awk {'......'}
>
>
> And also when(in what situation) these are used?
[...]

The second one should never be used.

The difference is at the shell level, not at the awk level.
'...' are strong shell quotes, which means that the text inside
single quotes is passed literally as one single argument to awk.

If you put "{" and "}" outside the quotes, they may be treated
specially depending on the shell.

For instance the bash, zsh and some versions of ksh shells (and
csh-like shells, but those have a different syntax), use {...}
to perform what is called brace expansion.

cmd foo{bar,baz}

is expanded into 3 arguments: "cmd", "foobar", "foobaz"

So in

awk {'print "'\'foo,bar\''"'}

awk would take three arguments: <awk>, <print "'foo> and <bar'">
which means run the <print "'foo> code on the file named
<bar'">, while in

awk '{print "'\'foo,bar\''"}'

awk would take two arguments: <awk> and <{print "'foo,bar'"}>
which means run the <{print "'foo,bar'"}> code on stdin.

awk {'print "foo"'}

would be the same as

awk '{print "foo"}'

(except for csh-like shells) as there's no unquoted commas
inbetween the braces (so, it's no candidate for brace
expansion).

--
Stephane

 0
Stephane
1/13/2005 9:00:32 AM
Thanks for the reply Stephane.

Similarly in what situations shud I use

awk '{........}'    < filename
AND

awk '{.........}'     filename

(The "<"  sign before filename)


 0
Anil
1/13/2005 10:03:40 AM
Anil wrote:
> Thanks for the reply Stephane.
>
> Similarly in what situations shud I use
>
> awk '{........}'    < filename

Here the shell reads the file and presents
it to standard input of the AWK interpreter.
The file name is unknown to AWK.

> AND
>
> awk '{.........}'     filename

Here it is the AWK interpreter which
opens the file and reads the data.
The FILENAME variable can be read in
this case.

Last week someone pointed out that the
second variant should be preferred over
the first one but I cant remember the
reason.

 0
ISO
1/13/2005 10:10:53 AM
2005-01-13, 02:03(-08), Anil:
> Thanks for the reply Stephane.
>
> Similarly in what situations shud I use
>
> awk '{........}'    < filename
> AND
>
> awk '{.........}'     filename
>
> (The "<"  sign before filename)

In the first case, the file is opened by the shell, in the
second, it is opened by awk.

You may prefer the first one as it makes a consistent way (with
consistent error messages) to open a file all along your script,
or to avoid problems with filenames containing equal signs (awk
take them for variable assignements if the = is not preceded by
a /). It also means that awk is not run if the shell can't open
the file (which saves some execution time).

You will prefer the second if there's more than one file to
open, or if you want awk to have access to the name of the file
(through FILENAME or ARGV variables).

If you need to open a file called file=name, use

awk '...' ./file=name

Or:

awk '...' < file=name

That means that:

awk '...' "$file" is not correct unless you've made sure$file can't be looking
like a variable assignment.

--
Stephane

 0
Stephane
1/13/2005 10:28:02 AM

Similar Artilces:

'is not' or '!='
A newbie question to you; what is the difference between statements like: if x is not None: and if x != None: Without any context, which one should be preferred? IMHO, the latter is more readable. On 2014-08-18 21:35, ElChino wrote: > A newbie question to you; what is the difference between statements > like: > if x is not None: > and > if x != None: > > Without any context, which one should be preferred? > IMHO, the latter is more readable. > "x == y" tells you whether x and y refer to objects that are equal. "x is y&qu...

'^=' and '~='?
Hello, What is the difference between '^=' and '~='? Thanks, Duckhye ...

'''''''''''''The Running Update/Append Queries Using VBA code Ordeal''''''''''''''
Hello fellow programmers, I am trying to run an append/update query from code, a command button on a form initiates the queries. the format i am using is; _____________________________________________________ SELECT "criteria" FROM "criteria" WHERE "criteria" UPDATE/APPEND "field selections" RecordSource "qryExample" = above text strings" _______________________________________________________________________ When i am running a SELECT query in this manner it works fine with no problems, and accepts the values of specified linked for...

'''''''''''''The Running Update/Append Queries Using VBA code Ordeal'''''''''''''' #2
Hi, Thanks for ur help there HJ. I know how to do the tasks you specified there. I would like for the update query to use field values from some of the fields on the form (frmInvoices) such as InvoiceNumber, DateFrom, DateTo. My problem is that an append/update query can't find the values in the open Form (frmInvoices) when I specify them as; [Forms]![frmInvoices]![InvoiceNumber] a select query has no problem finding the field values on a form. please help. Aaron Hi Aaron, Could you post the entire code that you are having trouble with? Now it is not possible to see what goes wron...

if str_mo not in ('','.') and str_da not in ('','.') and str_yy not in ('','.') Any shorter ?
Hi, there. =20 I'm just curious if it ever dawned on anybody how to abbreviate this line : if str_mo not in ('','.') and str_da not in ('','.') and str_yy not in ('','.')=20 =20 Igor Kurbeko Clinical Programmer Analyst 678 336 4328 ikurbeko@atherogenics.com =20 no brain no pain =20 how about: if not (str_mo in ('','.') or str_da in ('','.') or str_yy in ('','.')) OR if not (missing(str_mo) or missing(str_da) or missing(str_yy)) Eric On 22 Oct 03 21:13:37 GMT, ikurbeko@ATHER...

A function with 'and' , 'not' , 'null' , 'car' and 'cdr'
What's this ? (defun enigma (x) (and (not (null x)) (or (null (car x)) (enigma (cdr x))))) "I suppose I should learn Lisp, but it seems so foreign." - Paul Graham, Nov 1983 On Wed, Oct 07 2015, CAI GENGYANG wrote: > What's this ? > > > (defun enigma (x) > (and (not (null x)) > (or (null (car x)) > (enigma (cdr x))))) Bad taste? It returns T if the list X contains nil as an element. It would be clearer to write (some #'null x). Helmut CAI GENGYANG ...

Re: if str_mo not in ('','.') and str_da not in ('','.') and str_yy not in ('','.') Any shorter ?
OR you could use ARRAY data new; set old; array igor $(*) str_mo str_da str_yr; do over igor; if igor ~in (' ','.') then do; end; run; Prasad Ravi Igor Kurbeko <ikurbeko@ATHEROGENIC To: SAS-L@LISTSERV.UGA.EDU S.COM> cc: Sent by: "SAS(r) Subject: if str_mo not in ('','.') and str_da not in ('','.') and str_yy ... error: expected '=', ',', ';', 'asm' or '__attrib Hi I'm trying to compile an ADC Driver & come acrosss the following error. I've no experience writing drivers before, and hence have no clue how to fix it. Hope someone out there has encountered the problem & suggesst a fix for the same. The Error is I get is : qadc.c: At top level: qadc.c:97: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'qadc_read' make: *** [qadc.o] Error 1 [root@localhost qadc]# ########################################################################### ADC Driver Code ####################... error: expected '=', ',', ';', 'asm' or '__attrib Hi I'm trying to compile an ADC Driver & come acrosss the following error. I've no experience writing drivers before, and hence have no clue how to fix it. Hope someone out there has encountered the problem & suggesst a fix for the same. The Error is I get is : qadc.c: At top level: qadc.c:97: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'qadc_read' make: *** [qadc.o] Error 1 [root@localhost qadc]# ########################################################################### ADC Driver Code ##... Meaning of ':' and '{}' Hi, Please, can anyone tell me what is meaning of predicates ':' and '{}' ? ---------------- yours Advait Advait wrote: > Hi, > Please, can anyone tell me what is meaning of predicates ':' and '{}' > ? It depends on the context. : is used for module qualification of predicates. Like lists:member(X,L) The curly brackets are used in Definite Clauses Grammars: find the section on DCGs in the manual or google for it and you will find out easily. There are uses of {} as a functor in datastructures also. Cheers Bart Demoen Hello everyone,... Replacing ',' with '.' Hello, I have a huge amount of numbers in a .txt file. The numbers are in the form 2,43252e+1. I need to replace the , with . How should I do this? I'd prefer some import method that does this during the import procedure. -Janne Hi, I guess you import the data as text and convert it then to numbers. Try 'strrep' before you convert the text to numbers. Tobias Jake the Snake schrieb: > Hello, > > I have a huge amount of numbers in a .txt file. The numbers are in the form 2,43252e+1. I need to replace the , with . How should I do this? I'd prefer some import method... replacing '/' with '\\' I have a MKS ksh shell script running on a Windows box. In some scripts I have to convert a UNIX filename into a DOS filename, that is replace the '/' with '\\'. For example, replace /opt/siips/archive/text.dat with \\opt\\siips\\archive\\text.dat. I've tried using sed like$FILE='echo \$FILE|sed "s/\//\\\/g"' which got me \opt\siips\archive\text.dat. It's close but I still need the second \. Does anyone have any suggestion? Or tell me where I've gone wrong? Thanks -- Steffen On 9 Dec 2004 20:14:21 -0800, sajohn52@yahoo.com <sajohn52@yahoo....

replacement for '{' and '}' ?
I am still playing around with what kind of syntax I would like to mark up my documents. Are there equivalent long substitutes for { and } when they are not used to describe arguments to functions? Something like \begin{group} and \end{group}. In other words, if I could force myself to write, say, \begin{group} \it ... \end{group} instead of {\it ... }, then I believe I could identify from the markup context what is an argument that belongs to a just invoked macro and what is text. {Of course, in this context, \textit{...} would be better.} No more ambiguity whether a in \myfunction{a} i...

Does '!=' equivelent to 'is not'
I'm a bit confusing about whether "is not" equivelent to "!=" if a != b: ... if a is not b: ... What's the difference between "is not" and "!=" or they are the same thing? pirata wrote: > I'm a bit confusing about whether "is not" equivelent to "!=" > > if a != b: > ... > > if a is not b: > ... > > > What's the difference between "is not" and "!=" or they are the same thing? No, they are not the same thing. == and != test to see if the *value* of two ...

Web resources about - Diff between '{..}' and {'..'} - comp.lang.awk

Des Moines Register Endorses Clinton, Rubio
With just over a week to go before the Iowa Caucuses, the Hawkeye State’s largest newspaper has i ssued its endorsements in both the Republican ...

Giant Panda Plays In The Snow In Adorable Viral Video
It’s a well-known fact that kids love snow days. However, you might not know that giant pandas are also fond of snow — and playing in it. In ...

3 inmates escape California maximum-security jail: 'Expect the worst'
Chicago Tribune 3 inmates escape California maximum-security jail: 'Expect the worst' Chicago Tribune This image provided by the Orange County, ...

Sundance review: 'Manchester by the Sea' is a masterpiece about moving on
PARK CITY, Utah — How do we move on from unspeakable tragedy? From an untimely family death, from regrets and grief and horror and broken hearts? ...

Joe Biden: Vice President Claims The U.S. Prepared For ‘Military Solution’ Against Islamic State In Syria ...
One of the biggest issues the Obama administration had to deal with throughout their eight-year tenure is the threat of the Islamic State in ...

Magnitude 6.8 Earthquake Hits Alaska, Jolting Nerves
CBS Local Magnitude 6.8 Earthquake Hits Alaska, Jolting Nerves CBS Local ANCHORAGE (CBS/AP) — A magnitude-6.8 earthquake knocked items off ...

Canada school shooting: 17-year-old charged with murder
17-year-old Dayne Fountaine and 13-year-old Drayden, were shot dead in a home before the gunman headed to the grade 7-12 La Loche Community School. ...

Regulators order new steps to contain gas leak near Porter Ranch
Los Angeles Times Regulators order new steps to contain gas leak near Porter Ranch Los Angeles Times Regulators on Saturday approved a comprehensive ...

Blue Origin's reusable rocket pulls off the same trick again
There's something of a reusable rocket space race happening right now, as both Jeff Bezos' Blue Origin and Elon Musk's SpaceX battle it out to ...

Novak Djokovic’s Australian Open Struggle Is Kei Nishikori’s Opportunity – Preview
Novak Djokovic learned first-hand at the Australian Open this morning just why Gilles Simon has been nicknamed “The Grinder” on the ATP Tour. ...

Resources last updated: 1/24/2016 4:23:48 PM