LC to UC selectively
I have a file that looks like this:
poly poly
metal1 metal1
metal2 metal2
metal3 metal3
but need to be able to change one column to uppercase so either:
POLY poly
Re: LC to UC selectively
rickm [at] galaxy.nsc.com wrote:
> I have a file that looks like this:
>
> poly poly
> metal1 metal1
> metal2 metal2
> metal3 metal3
>
> but need to be able to change one column to uppercase so either:
>
> POLY poly
>
I would try:
typeset -u UC
while read UC LC
do
echo "$UC \t $LC"
done < input_file
Re: LC to UC selectively
Johann Kappacher wrote:
> rickm [at] galaxy.nsc.com wrote:
>> I have a file that looks like this:
>>
>> poly poly
>> metal1 metal1
>> metal2 metal2
>> metal3 metal3
>>
>> but need to be able to change one column to uppercase so either:
>>
>> POLY poly
>>
> I would try:
>
> typeset -u UC
>
> while read UC LC
> do
> echo "$UC \t $LC"
> done < input_file
>
Perhaps, you will need to change the IFS (Input Field Separator) first.
Please, check man page or tutorial for bash or ksh.
Re: LC to UC selectively
On 4/7/2008 2:16 PM, rickm [at] galaxy.nsc.com wrote:
> I have a file that looks like this:
>
> poly poly
> metal1 metal1
> metal2 metal2
> metal3 metal3
>
> but need to be able to change one column to uppercase so either:
>
> POLY poly
>
This may be what you want if you don't care about preserving the white-space:
awk '{$1=toupper($1)}1' file
If you do care, tell us what that white space is.
Ed.
Re: LC to UC selectively
Ed Morton wrote:
> awk '{$1=toupper($1)}1' file
Nice solution, not strict shell, but very nice!
btw: what stands the 3rd "1" for?
--jk
Re: LC to UC selectively
Johann Kappacher wrote:
> Ed Morton wrote:
>
>> awk '{$1=toupper($1)}1' file
> Nice solution, not strict shell, but very nice!
>
> btw: what stands the 3rd "1" for?
Brrr, shame on me, this is true Pidgin English!
I would prefer a perlish approach, but this is comp.unix.shell ...
Re: LC to UC selectively
On 4/7/2008 4:33 PM, Johann Kappacher wrote:
> Ed Morton wrote:
>
>
>> awk '{$1=toupper($1)}1' file
>
> Nice solution, not strict shell, but very nice!
People who post questions here are rarely looking for solutions that only
involve shell builtins (if that's what you mean by "strict shell") but instead
are happy with any tools called from the shell (tr, grep, sed, awk, etc...).
> btw: what stands the 3rd "1" for?
It's a true condition which invokes the default action of printing the current
record.
Ed.
Re: LC to UC selectively
In article <47FA9926.6060209 [at] lsupcaemnt.com>,
Ed Morton <morton [at] lsupcaemnt.com> wrote:
> On 4/7/2008 4:33 PM, Johann Kappacher wrote:
> > Ed Morton wrote:
> >
> >
> >> awk '{$1=toupper($1)}1' file
> >
> > Nice solution, not strict shell, but very nice!
>
> People who post questions here are rarely looking for solutions that only
> involve shell builtins (if that's what you mean by "strict shell") but instead
> are happy with any tools called from the shell (tr, grep, sed, awk, etc...).
>
> > btw: what stands the 3rd "1" for?
>
> It's a true condition which invokes the default action of printing the current
> record.
I.e. a more terse, but less clear, way of writing
awk '{$1=toupper($1); print}' file
--
Barry Margolin, barmar [at] alum.mit.edu
Arlington, MA
*** PLEASE don't copy me on replies, I'll read them in the group ***
Re: LC to UC selectively
On 4/7/2008 9:07 PM, Barry Margolin wrote:
> In article <47FA9926.6060209 [at] lsupcaemnt.com>,
> Ed Morton <morton [at] lsupcaemnt.com> wrote:
>
>
>>On 4/7/2008 4:33 PM, Johann Kappacher wrote:
>>
>>>Ed Morton wrote:
>>>
>>>
>>>
>>>> awk '{$1=toupper($1)}1' file
>>>
>>>Nice solution, not strict shell, but very nice!
>>
>>People who post questions here are rarely looking for solutions that only
>>involve shell builtins (if that's what you mean by "strict shell") but instead
>>are happy with any tools called from the shell (tr, grep, sed, awk, etc...).
>>
>>
>>>btw: what stands the 3rd "1" for?
>>
>>It's a true condition which invokes the default action of printing the current
>>record.
>
>
> I.e. a more terse, but less clear, way of writing
>
> awk '{$1=toupper($1); print}' file
>
which is itself a more terse, but less clear, way of writing
awk '{$1=toupper($1); print $0}' file
we could go on adding language constructs, but using "1" that way is a very
common awk idiom so it's worth getting used to.
Ed.
Re: LC to UC selectively
Ed Morton wrote:
> which is itself a more terse, but less clear, way of writing
>
> awk '{$1=toupper($1); print $0}' file
>
> we could go on adding language constructs, but using "1" that way is a
> very common awk idiom so it's worth getting used to.
This should work as well, right? It seems to work for me.
awk '$1=toupper($1)' file
Thanks
--
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.
Re: LC to UC selectively
pk wrote:
> This should work as well, right? It seems to work for me.
>
> awk '$1=toupper($1)' file
Ok, it there are no empty lines, of course.
--
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.
Re: LC to UC selectively
On 4/8/2008 3:10 AM, pk wrote:
> pk wrote:
>
>
>>This should work as well, right? It seems to work for me.
>>
>>awk '$1=toupper($1)' file
>
>
> Ok, it there are no empty lines, of course.
>
Right. That's the caveat.
Ed.
Re: LC to UC selectively
In article <47FB5E28.1040305 [at] lsupcaemnt.com>,
Ed Morton <morton [at] lsupcaemnt.com> wrote:
>
>
>On 4/8/2008 3:10 AM, pk wrote:
>> pk wrote:
>>
>>
>>>This should work as well, right? It seems to work for me.
>>>
>>>awk '$1=toupper($1)' file
>>
>>
>> Ok, it there are no empty lines, of course.
>>
>
>Right. That's the caveat.
>
> Ed.
>
Or if you don't care about the blank lines. Which, for me, is often the
case. If the file comes from less reliable sources, those less reliable
sources often put blank lines in the files they send me, for no good reason.