multiple awk commands

gudii9
gudii9 used Ask the Experts™
on
how to grep multiple awks

$ awk '{print;}' employee.txt
100  Thomas  Manager    Sales       $5,000
200  Jason   Developer  Technology  $5,500
300  Sanjay  Sysadmin   Technology  $7,000
400  Nisha   Manager    Marketing   $9,500
500  Randy   DBA        Technology  $6,000


$ awk '{print $2,$5;}' employee.txt
Thomas $5,000
Jason $5,500
Sanjay $7,000
Nisha $9,500
Randy $6,000

in above query how to tweak to see  see all records whose name starts with 'S' and Salary greater than '6000'

also
in above query how to tweak to see  see all records whose name starts with 'S' and Salary greater than '6000' and Department Starts with  'T'


100  Thomas  Manager    Sales       $5,000     08/08/1988 6:00:01AM
200  Jason   Developer  Technology  $5,500 08/08/1989 7:00:02AM
300  Sanjay  Sysadmin   Technology  $7,000 08/08/1982 9:00:03AM
400  Nisha   Manager    Marketing   $9,500 08/08/1981 10:00:04AM
500  Randy   DBA        Technology  $6,000 08/08/1981 11:00:5AM
if it has joined date and time as above
in above query how to tweak to see  see all records whose name starts with 'S' and Salary greater than '6000' and Department Starts with  'T' and joined between particular date time to particular date time say  08/08/1982 9:00:03 AM till 08/08/1981 10:00:04AM
i need to use above in a zgrep command

https://www.thegeekstuff.com/2010/01/awk-introduction-tutorial-7-awk-print-examples/
http://www.theunixschool.com/2012/09/grep-vs-awk-examples-for-pattern-search.html

Please advise
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
nociSoftware Engineer
Distinguished Expert 2018
Commented:
Should be easy:  
$ awk '{print $2,$5;}' employee.txt | egrep '^S[^ ]* \$[789],'
Sanjay $7,000

Open in new window

Right answer?,, well there is a problem here can you tell me what it is?
So maybe not the right one.  

More a Pure AWK solution...
 awk '{X=substr($5,2); sub(",","",X); if (substr($2,1,1)=="S" && substr($4,1,1)=="T" && X > 6000) { print $2,$4,$5;}}' employee.txt 
Sanjay Technology $7,000

Open in new window



Please check the awk man page  https://linux.die.net/man/1/awk for more info to solve the last Q....
PLease take a stab at it and show the result (or the part you could accieve).
Distinguished Expert 2017
Commented:
Noci covered...
Awk parser, separates fields based on white space in the example, with the first element stored in $1 with NF representing the number of fields. In a line.


When processing text, look at using perl provides a single mechanism that does not need to hand off ....
Shell_script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX C C++ CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NT
Commented:
#Noci covered...
#:)
/usr/bin/awk '{
                X=substr($5,2);
                sub(",","",X);
                if ( substr($2,1,1)=="S" && substr($4,1,1)=="T" && X > 6000 )
                {
                        print $2,$4,$5;
                }
}' employee.txt
#@gudii9
# Use values on the left and variables/functions on the right during comparison.
# We can also use substr( $NF, 2, length( $NF) )
# Use related path when using any execuable/files ./employee.txt
/bin/awk '{
        if ( ( "S" == substr( $2, 1, 1) ) && ( "T" == substr( $4, 1, 1) ) && ( 6000 < substr( $NF, 2 , length( $NF) ) ) )
        {
                printf( "%s %s %s\n", $2, $4, $NF);
        }
}' ./employee.txt

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial