The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grep or Tail in shell script Moxy Shell Programming and Scripting 3 08-03-2008 10:36 PM
grep in Shell script Krishnaramjis Shell Programming and Scripting 1 02-19-2008 09:43 PM
grep, sed in a shell script Trufla Shell Programming and Scripting 4 04-07-2005 09:57 AM
Using Grep in a Shell Script nbvcxzdz Shell Programming and Scripting 8 03-19-2005 05:21 AM
grep doesn't work within shell script? barisgultekin Shell Programming and Scripting 4 05-24-2002 03:01 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 08-06-2008
nick_25 nick_25 is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 4
grep, awk, typeset in a shell script..

For e.g I have a file named "relation" which has three coloums i.e

JOHN MARY JACK
PETE ALISIA JONNY
TONY JACKIE VICTOR

If I do
grep -w 'JOHN' relation | awk '{print""$1" is husband of "$2" & father of "$3""}'

It gives out
JOHN i husband of MARY & father of JACK (which is desired output for me)

I put this thing into script but it stops working. All I am doing is to change the input in Upper case & using grep, awk after that.

#!/usr/bin/ksh
name=$1
print "$name"
echo "$name" | tr '[a-z]' '[A-Z]' >$NAME
print "$NAME"
grep -w "$NAME" relation |awk '{print""$1" is husband of "$2" & father of "$3""}' >$out
print "$out"
exit 0

If I run it like ./scriptname john
it gives output
john
JOHN

Can anyone plz help me to fix it..

I had given an example.
  #2 (permalink)  
Old 08-06-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
This line is incorrect. Insted of assigning the result to the variable NAME, you are redirecting the output of the command to a file, whose name is stored in the variable NAME (which I presume is currently undefined).


Code:
echo "$name" | tr '[a-z]' '[A-Z]' >$NAME

I think this will give the result you expect:


Code:
name=$(echo "$name" | tr '[a-z]' '[A-Z]')
# or this, but I prefer the previous syntax
name=`echo "$name" | tr '[a-z]' '[A-Z]'`

Similarly with $out, you need to make the same change.
  #3 (permalink)  
Old 08-07-2008
summer_cherry summer_cherry is online now Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,099

Code:
nawk '{print toupper($1)" is husband of"toupper($2)" & father of "toupper($3)}' filename

  #4 (permalink)  
Old 08-07-2008
nick_25 nick_25 is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 4
Quote:
Originally Posted by summer_cherry View Post
Code:
nawk '{print toupper($1)" is husband of"toupper($2)" & father of "toupper($3)}' filename
Thanks for the reply but this thing won't work since I am converting lowercase to Uppercase so that the grep can work b'coz in the file everything is in uppercase. I m doing something wrong in grep statement not in awk one.
  #5 (permalink)  
Old 08-07-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
What does your code look like now?

Have you made the same change to the grep line as I recommended for the tr line?
  #6 (permalink)  
Old 08-07-2008
nick_25 nick_25 is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 4
Quote:
Originally Posted by Annihilannic View Post
What does your code look like now?

Have you made the same change to the grep line as I recommended for the tr line?
Will try that when I go to office tommorow..Thanks for the help.
  #7 (permalink)  
Old 08-07-2008
nick_25 nick_25 is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 4
Quote:
Originally Posted by Annihilannic View Post
What does your code look like now?

Have you made the same change to the grep line as I recommended for the tr line?
Thanks Annihilannic everything works now.
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:11 AM.


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