Searching value in table through awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Searching value in table through awk
# 1  
Old 04-22-2015
Searching value in table through awk

I need to create one script in which I want to search in txt file , this txt file is having 10 columns , I want to check 4th column value if "BOY" & 10th column value =>500 it will print 4th column row value ,1st column row value & 10th column row value & store the same value in one file as following : BOY is running from last 500 Sec.
I have created but it is not working :-
Code:
LOGDIR=/file/location/

export MAIL_LIST="xxx@in.xxx.com"
var=$(
cat `find $LOGDIR -type f|sort -r|head -n1` | while read line
do
awk '{
if ($3 -eq "BOY" && $10 >= 500) echo "$3 is running in "$1" from last  "$10" secs"
     }'
done)
echo $var

it is giving the output but different row value which is greater than 500.

Last edited by Don Cragun; 04-22-2015 at 06:47 PM.. Reason: Fix CODE tags.
# 2  
Old 04-22-2015
I can't tell what half your code is supposed to be doing.

The combination of find, cat, read, and awk you have here is almost certainmly not going to do what you want no matter what you put in any of them.

I think, but can only guess, that this is what you want:

Code:
FILE="$(find $LOGDIR -type f|sort -r|head -n1)"

awk '($3 == "BOY") && (($10+0) >= 500) { print $3" is running in "$1" from last "$10" secs"; }' "$FILE"

Without any input data to test on this is the best I can do.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 04-23-2015
Thanks for your reply Corona,
I have tried your code but it is giving output all other values in tables but not which want.I am giving you table example.
Code:
Column1    column2  column3 
BOY         200             passed           
GIRL         300             passed
CHILD      100             passed
BOY          500           passed
MAN         50            failed
BOY           50              failed

I want if BOY is greater than 50 print column 3 value of the same row.
$Column1 marks is Coulmn2 ,so passed/failed
output will be like this :-(it should show boy value only)
Code:
BOY marks is 200 so passed
BOY marks is 500 so passed
BOY marks is 50 so  failed

but I have tried your query it is showing all other values except boy.
Code:
Girl marks is 300 so passed
Child marks is 100 so passed.
Man marks is 50 so failed.

kindly help .

---------- Post updated at 05:19 PM ---------- Previous update was at 03:45 PM ----------

Thanks for your reply Corona,

I have done some mistake, what you have suggested that is working very much, I am very sorry for that.
Just I want to give thanks icon to you but I do not have idea how to give in this forum.
once again thanks for your valuable suggestion & time.Smilie
Kindly suggest.

Last edited by vgersh99; 04-23-2015 at 06:31 PM.. Reason: "kindly" use code tags!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to convert table-by-row to matrix table

Hello, I need some help to reformat this table-by-row to matrix? infile: site1 A:o,p,q,r,s,t site1 C:y,u site1 T:v,w site1 -:x,z site2 A:p,r,t,v,w,z site2 C:u,y site2 G:q,s site2 -:o,x site3 A:o,q,s,t,u,z site3 C:y site3 T:v,w,x site3 -:p,routfile: SITE o p q r s t v u w x y... (7 Replies)
Discussion started by: yifangt
7 Replies

2. Shell Programming and Scripting

Searching multiple patterns using awk

Hello, I have the following input file: qh1adm 20130710111201 : tp import all QH1 u6 -Dsourcesystems=BFI,EBJ qh1adm 20130711151154 : tp import all QH1 u6 -Dsourcesystems=BFI,EBJ qx1adm 20130711151154 : tp count QX1 u6 -Dsourcesystems=B17,E17,EE7 qh1adm 20130711151155 : tp import all... (7 Replies)
Discussion started by: kcboy
7 Replies

3. Shell Programming and Scripting

awk: searching for non-breaking-space

This code shal search for the non-breaking space 0xA0 though it returns the error "fatal: attempt to use scalar 'nbs' as array" Can somebody help? awk --non-decimal-data -v nbs="0xA0" '{if($0 in nbs) {print FILENAME, NR}}' *.txt (1 Reply)
Discussion started by: sdf
1 Replies

4. Shell Programming and Scripting

Searching a file using awk or sed

I want to search a file in a specific location and I don't want to use find command. I want to give the path also where the file is for searching it. Pls help (3 Replies)
Discussion started by: maitree
3 Replies

5. Shell Programming and Scripting

awk searching

hi all, Please can you help me with the awk searching where: I have a master file where I need the string $12. the string $ 12 varies between 3 and 4 characters and I need to bring only the characters ending in 68. try this, but is so bad my search i know awk-F, '(if... (8 Replies)
Discussion started by: manzi
8 Replies

6. Shell Programming and Scripting

Searching using awk - Help required

Hi... I am working on script to search some records in a file based on certain fields and each record is a ASCII fixed size. I was using awk to search based on certain condition. But the length of the record is too much that awk is giving syntax error near unexpected token `(' Request... (5 Replies)
Discussion started by: ysrikanth
5 Replies

7. Shell Programming and Scripting

awk and searching within a block ?

Hi, I wonder if anybody could help. How do i awk out (or indeed using another utility) a particular value that exists within a defined block, for example if i have a file that looks like the one below and i want to get at the "Product Serial" for the block referring to "mb.fru" (bolded and coloured... (4 Replies)
Discussion started by: rethink
4 Replies

8. Shell Programming and Scripting

Searching word in a file with awk

Hello everyone! I use a script to query for installed packages with yum (I use RHEL 4 with yum installed) and the output is redirected to a file. My script scan this file to find a package and the version of it. The script works fine until I search for a package name with special characters.... (3 Replies)
Discussion started by: studieu
3 Replies

9. Shell Programming and Scripting

problem while searching in a file by 'AWK'

Hi , i am writing a script in which i am using following command to grep some string and then storing it's output to v, as like below :- v=$(awk -F, '{ if ( $NF ~ /DEV/ ) print $0 "_BLD01";else print $0 "_RC01" }' mytest) Here i am facing following issues:- 1. it is searcing DEV in the... (1 Reply)
Discussion started by: inderpunj
1 Replies

10. Shell Programming and Scripting

awk searching between two files

hi there, im writing some script in awk; in few words i have a list from router (mac address- ip address) and the second list with only the mac addresses. the thing is that i want search list from router for the first mac address; if found - print the ip address, if not print error; then search... (1 Reply)
Discussion started by: mac7
1 Replies
Login or Register to Ask a Question