[ale] simple awk tolower question

Greg Freemyer greg.freemyer at gmail.com
Mon Mar 28 14:34:38 EST 2005


On Mon, 28 Mar 2005 14:19:23 -0500, Christopher Bergeron
<christopher at bergeron.com> wrote:
> Can anyone help me with this one?  It's an apparently simple awk
> statement, however, I'm not getting the expected result.
> 
> I have a text file that has a name in it (/tmp/new_users.txt).
> 
> $ cat /tmp/new_users.txt
> Smith
> 
> I'm trying to convert it to lower case.  Easy enough right?  Here's what
> I'm trying:
> 
> $ awk "{ print tolower($1) }" /tmp/new_users.txt
> awk: cmd. line:1: fatal: 0 is invalid as number of arguments for tolower
> 
> The file may contain multiple lines, so I'd like to convert all the
> lines to all lowercase.  I won't have any funny characters, just
> alphanumeric.
> 
> Any ideas?
> 
> Thanks in advance to they whom help me.
> -CB

Your trying to pass "$1" to awk, right?

If so, you need single quotes I think

awk '{ print tolower($1) }' /tmp/new_users.txt

or try a '\' in front of the $ sign, like

awk "{ print tolower(\$1) }" /tmp/new_users.txt

And finally, you talk about lines.  IIRC $0 is the entire line, not
$1.  $1 is just the first field.
 
FYI: You can also do this with tr I believe, and tr is easier to use
for simple tasks.

-- 
Greg
-- 
Greg Freemyer
The Norcross Group
Forensics for the 21st Century



More information about the Ale mailing list