![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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. |
|
||||
|
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. |
|
||||
|
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.
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|