Link to home
Start Free TrialLog in
Avatar of Swaminathan K
Swaminathan KFlag for India

asked on

Need help on grep command

Hi Team,

I have the below file .
ID            Name      Hours Worked      Hourly Pay
1425      Juan      18                        14.25
4321      George      22                        21.11
6781      Anne      44                        16.77
1451      Ben            36                        21.77
2277      Tuan      16                        18.77

I need help on the below comamnds on grep, Iam new to grep

I need to display the hourly pay of anne (only the last field )
using grep command.

Secondly , One line comamnd to find the id and hours worked for employees who earn more than $20 per hour.
ASKER CERTIFIED SOLUTION
Avatar of Sujith
Sujith
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If the fields are tab delimited then it should be straight forward:

grep Anne <file> | cut -f4

Again, if tab delimited the second one should be:

grep [2-9][0-9]\.[0-9][0-9] <file> | cut -f1

I have a feeling though that your file isn't tab delimited.
Grep is a tool to match patterns
As others pointed out other tools, commands need to be used to meet your need.

Your second question
cat fileofdata.txt | awk ' ($4>=20) {print $2,$4 }'
The default when -F is not used to designate the delimiter to ve use to break up the data on a line is white space, which would include combinations of spaces, and I velum E tabs.

The condition is To evaluate whether the last column is greater than 20, iwhen it is the name and the hourly is reported.

Where is this data coming from, it might be better to search through the source if database, or similar....