hi guys i have a problem here, im trying to stablish a relationship between a text file and an input user for example the script is going to prompt the user for some football team and what the script is going to do is return the colums in which that input is located so far this is what i have
#!/bin/bash
echo -n "Enter Team: "
read team
for line in `cut -f2 -d: nhl_data | grep "$team"`
do
echo $line
done | awk -F: '{printf "%s\n",
any assistance or suggestionswil be greatly appreciated
thanks
If I'm not missing something, using a loop is not necessary this should be sufficient:
grep "$team" nhl_data
Regards
yeah that help me alot thanks my friend ............. but now i have another problem once grep finds that specific keyword , i want to print the columns that are related to that keyword, for example the keyword is located at field $2 in other words all the keywords are going to come from field $2, i want the script to scan each line from the file and everytime it finds that keyword is going to print fields $1 and fields $4 ............... ..... any suggestions are greatly appreciated thank you guys
It should be something like this:
awk -v t=$team '$2==t{print $1, $4}' nhl_data
Regards
so far this is how script looks
#!/bin/bash
echo -n "Enter Team: "
read team
awk -v t- $team '$2--t{print $1, $4}' nhl_data
when i run the script i get an error message like this
awk: `t-' argument to `-v' not in `var=value' form
Usage: awk [POSIX or GNU style options] -f progfile [--] file ...
Usage: awk [POSIX or GNU style options] [--] 'program' file ...
POSIX options: GNU long options:
-f progfile --file=progfile
-F fs --field-separator=fs
-v var=val --assign=var=val
-m[fr] val
-W compat --compat
-W copyleft --copyleft
-W copyright --copyright
-W dump-variables[=file] --dump-variables[=file]
-W exec=file --exec=file
-W gen-po --gen-po
-W help --help
-W lint[=fatal] --lint[=fatal]
-W lint-old --lint-old
-W non-decimal-data --non-decimal-data
-W profile[=file] --profile[=file]
-W posix --posix
-W re-interval --re-interval
-W source=program-text --source=program-text
-W traditional --traditional
-W usage --usage
-W version --version
To report bugs, see node `Bugs' in `gawk.info', which is
section `Reporting Problems and Bugs' in the printed version.
gawk is a pattern scanning and processing language.
By default it reads standard input and writes standard output.
Examples:
gawk '{ sum += $1 }; END { print sum }' file
gawk -F: '{ print $1 }' /etc/passwd
regards
fanklin thanks my friend i finally got it this is how it came out
grep "$team" nhl_data | awk -F: '{printf "%s\n", $1}'
thank your you help my friend ........ keep up the good work
Your code:
awk -v t- $team '$2--t{print $1, $4}' nhl_data
must be:
awk -v t=$team '$2==t{print $1, $4}' nhl_data
Regards