LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-09-2006, 10:14 PM   #1
bhert
Member
 
Registered: May 2006
Distribution: OpenSUSE 10.3 Kubuntu Hardy Heron
Posts: 268

Rep: Reputation: 30
scripting problem


Hello, I am still considered a newbie and I am still learning when it comes down to a little bit of scripting. Here is my problem:
I will show you what the file looks like when I cat it:

2233|charles harris |g.m. |sales |12/12/52| 90000
9876|bill johnson |director |production|03/12/50|130000

The list is longer, I just shortened it to show what it looks like.

What I want is to chang the person's names in the second field from lower case to upper case using some kind of loop. Now I tried using cut, grep, sed commands and the for loop and I can't quite get it to work right. I know it's probably a simple thing to do. Help me please. Thanks

-bhert
 
Old 10-09-2006, 10:59 PM   #2
Moy Easwaran
Member
 
Registered: Dec 2004
Distribution: Slackware, OpenBSD
Posts: 44

Rep: Reputation: 19
man awk(1)
http://www.gnu.org/software/gawk/manual/gawk.html

Something like the following should work:
Code:
awk -F\| '{print toupper($2)}'
awk thinks of lines as records; -F| tells it to use | as a field separator and $2 tells it to use the second field.

Moy
 
Old 10-09-2006, 11:12 PM   #3
hepburnenthorpe
Member
 
Registered: Jun 2006
Location: Sydney
Distribution: Gentoo + Debian
Posts: 132

Rep: Reputation: 15
Probably easier ways, but this should work. Change all ocurences of out.txt to the name of your file.
Code:
cat out.txt | awk -F"|" '{print $1"|" toupper($2)"|" $3"|" $4"|"$5"|" $6}' > /tmp/out && cat /tmp/out > out.txt && rm /tmp/out
 
Old 10-09-2006, 11:36 PM   #4
bhert
Member
 
Registered: May 2006
Distribution: OpenSUSE 10.3 Kubuntu Hardy Heron
Posts: 268

Original Poster
Rep: Reputation: 30
Thanks for the help Moy. For some reason I forgot about awk.
Here is the code I made:

Code:
awk -F "|" '{ print ($1)"|" toupper ($2)"|"($3)"|"($4)"|"($5)"|"($6) }' emp > emp1
The result when I cat the new file:

2233|CHARLES HARRIS |g.m. |sales |12/12/52| 90000
9876|BILL JOHNSON |director |production|03/12/50|130000

Thanks again, I am going to read some more about awk

-bhert
 
Old 10-10-2006, 01:24 AM   #5
bhert
Member
 
Registered: May 2006
Distribution: OpenSUSE 10.3 Kubuntu Hardy Heron
Posts: 268

Original Poster
Rep: Reputation: 30
hepburnenthorpe, I didn't see your post after I posted my code. I was surprised that it's pretty much the same as mine except for the redirection to /tmp and back to the file. Thanks for putting it up.

-bhert
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
scripting problem rm filelist milke Programming 9 07-07-2006 06:41 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 05:29 AM
bash scripting problem Sammy2ooo Linux - General 3 12-13-2004 01:31 PM
samba scripting problem mehesque Linux - Networking 1 12-04-2003 12:10 PM
scripting problem,its annoying roo Linux - Newbie 2 04-02-2003 04:47 AM


All times are GMT -5. The time now is 01:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration