File Processing

Hi ALL,

I have below file generated as o/p after my java code runs,

Student Id 22552530 Below is the size
(22ms, 835 bytes
Student Id 2124592 Below is the size
(55ms, 703 bytes
Student Id 23903104 Below is the size
(46ms, 24333 bytes
Student Id 23903104 Below is the size
(61ms, 24333 bytes
Student Id 23903104 Below is the size
(8ms, 24333 bytes
Student Id 23903104 Below is the size
(129ms, 24333 bytes
Student Id 21246414 Below is the size
(133ms, 28601 bytes
Student Id 23906410 Below is the size
(21ms, 1520 bytes

[/CODE]

I wanted all the Student id's whose size exceeds 1000 bytes

Hello nikhil jain,

If you want duplicates into your answer then following may help you in same.

awk '/Student/{A=$0;next} /bytes/ && A && $2 > 1000{print A;A=""}'   Input_file

If you don't want to get duplicates then following may help you in same.

awk '/Student/{B=$3;A=$0;!C++;next} /bytes/ && C==1 && $2 > 1000{print A}'  Input_file

Thanks,
R. Singh

1 Like

Hi Ravinder

Thanks a lot :slight_smile: It did worked.

---------- Post updated 03-29-17 at 01:02 PM ---------- Previous update was 03-28-17 at 05:04 PM ----------

awk '/Student/{B=$3;A=$0;!C++;next} /bytes/ && C==1 && A=0{print A}'  Input_file

The above code does not work, if i want to find the size with 0 bytes. Can anyone please look into it and make the code correct.

Hello nikhil jain,

You are using assignment operator, it should be as follows.

awk '/Student/{B=$3;A=$0;!C++;next} /bytes/ && C==1 && $2==0{print A}'   Input_file

Thanks,
R. Singh