The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Convert character in word to CAPS?? vadharah Shell Programming and Scripting 3 04-01-2008 08:44 AM
how to read the column and print the values under that column gemini106 Shell Programming and Scripting 6 03-28-2008 07:05 AM
Convert Header into Column in Text file vsubbu1000 Shell Programming and Scripting 7 08-06-2007 05:09 AM
Retrieve line from a file based on a value in specific column efernandes UNIX for Dummies Questions & Answers 1 01-27-2007 11:04 AM
How to read from a file line by line and do stuff spaceship Shell Programming and Scripting 4 03-17-2005 09:47 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-31-2007
orahi001 orahi001 is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 48
read a line from a csv file and convert a column to all caps

Hello experts,

I am trying to read a line from a csv file that contains '.doc' and print the second column in all caps.

e.g.

My csv file contains:
Test.doc|This is a Test|test1|tes,t2|test-3
Test2.pdf|This is a Second Test| test1|tes,t2|t-est3

while read line
do
echo "$line" | awk -F '|' '/.doc/ {print toupper($2)}'
done < $dataFile


output:
This is a Test


I've been trying to use the toupper function of awk but it does not convert to upper case.

Anyone know another way this can be done?


thanks
  #2 (permalink)  
Old 12-31-2007
awk awk is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 134
Hate to tell you this, but it worked for me on an AIX box. I cut and paste your code as is.

Perhaps, if you are on Solaris, try nawk instead.

Wouldn't it be simpler to just do:

awk -F '|' '/[.]doc/ {print toupper($2)}' datafile
  #3 (permalink)  
Old 12-31-2007
drl's Avatar
drl drl is online now Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 717
Hi.

It worked for me as well:

Code:
#!/usr/bin/env sh

# @(#) a1       Demonstrate awk toupper function.

set -o nounset
echo

## Use local command version for the commands in this demonstration.

echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version bash awk

echo

# Use nawk or /usr/xpg4/bin/awk on Solaris.

cat >data1 <<'EOF'
Test.doc|This is a Test|test1|tes,t2|test-3
Test2.pdf|This is a Second Test| test1|tes,t2|t-est3
EOF

FILE=${1-data1}

echo
echo " Input file $FILE:"
cat $FILE

echo
echo " Results from awk:"
awk -F '|' '
/.doc/ {print toupper($2)}
' $FILE

exit 0

Producing:

Code:
% ./a1

(Versions displayed with local utility "version")
GNU bash 2.05b.0
GNU Awk 3.1.4


 Input file data1:
Test.doc|This is a Test|test1|tes,t2|test-3
Test2.pdf|This is a Second Test| test1|tes,t2|t-est3

 Results from awk:
THIS IS A TEST

Best wishes ... cheers, drl
  #4 (permalink)  
Old 12-31-2007
orahi001 orahi001 is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 48
Hi again,


thanks for the feedback...I used nawk as suggested and it worked.

awk -F '|' '/[.]doc/ {print toupper($2)}' datafile

is definitely simpler than what I have...I'm a newbie to unix scripting so I of course made something more complicated than it should be

thanks for the help
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:57 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0