Computing.Net > Forums > Unix > awk problem: loveunix newbie

awk problem: loveunix newbie

Reply to Message Icon

Original Message
Name: surfdude
Date: April 25, 2003 at 14:12:53 Pacific
Subject: awk problem: loveunix newbie
OS: unix
CPU/Ram: athlon 1700xp 256mb
Comment:

Hi everyone,

I am working on a small language translation program, and am stuck trying to use awk.
I have so far created three files:
1. main menu file
2. lookup file with awk, which is called from main menu file
3. language file containing english, french and serbian words, like:

sea mer more
water eau voda

I want user to enter english word, and french equivalent should appear on the screen. I want to store user input - like 'car' into variable, which is then used as search term. Once line containing 'car' is found, I want to display word in second column ($2), which is french equivalent.

This is my code:

echo "Enter the word in english:"
read string
echo "Same word in french is:"
awk $1=$string '{print $2}' lang_words.txt
echo
echo "press any key to continue"
read key

I get ^ parse error when trying to run this, and have tried all combinations on this theme, but to no avail. Can somebody help me get over this, as I have no other ideas.


Report Offensive Message For Removal


Response Number 1
Name: nails
Date: April 25, 2003 at 14:28:39 Pacific
Subject: awk problem: loveunix newbie
Reply: (edit)

Hi:


#!/bin/ksh

echo "Enter the word in english:"
read string
echo "Same word in french is:"
awk ' { if ($1 == word)
print $2 }' word="$string" lang_words.txt
echo
echo "press any key to continue"
read key

Regards,

Nails


Report Offensive Follow Up For Removal

Response Number 2
Name: surfdude
Date: April 25, 2003 at 15:20:14 Pacific
Subject: awk problem: loveunix newbie
Reply: (edit)

Nails, that is awesome, worked first time.

Thank you for your prompt response. Now onwards and upwards until I hit another problem!


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: awk problem: loveunix newbie

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge