Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk command 1

Status
Not open for further replies.

PatelRam

Programmer
Aug 20, 2003
87
US
FILE 1
======
102,MALE ,JOHN,1000
103,FEMALE,TINA,2000
104,MALE ,RAJA,3000
105,FEMALE,SARA,4000


I have file above and i need to get all the record which start position from 5-10 (MALE).

i don't how to use awk command to get following output


FILE 1
======
102,MALE ,JOHN,1000
104,MALE ,RAJA,3000


Thanks,

Ram
 
Do you need to use awk? Why not just use &quot;grep MAN <file>&quot;

I love deadlines. I like the whooshing sound they make as they fly by - Douglas Adams
 
Sorry should be grep &quot;,MALE&quot; <file>

I love deadlines. I like the whooshing sound they make as they fly by - Douglas Adams
 
I can not use grep because &quot;MALE&quot; WORD is also repeating in OTHER field.

like second eg.

OFX,102,AWIS
TRS,203,BOFX <---Note i do not want this record
OFX,303,CSIS
TRS,404,DSOS
OFX,505,ES10

I need all the record whoes first field value
is OFX ie (1-3)
 
grep '^OFX' <file> will find all lines that begin (^) with OFX.

I love deadlines. I like the whooshing sound they make as they fly by - Douglas Adams
 
sorry may be i am not giving proper example
HERE IS THE CORRECT EXAMPLE

how do i get all the records with 4-6 position OFX ie
record no 1,2 and 4

AXBOFX123
282OFX456
929233789
DJDOFX101
383OPS202

 
If you insist on using awk then..

awk '{if(substr($1,4,3)==&quot;OFX&quot;) print $0}' <filename> should do it

I love deadlines. I like the whooshing sound they make as they fly by - Douglas Adams
 
You can still use grep with fixed position, like..

grep '^...OFX' $file

where

^ = the start of line marker
. = any printable character

Note that some greps may require the -E option.
 
For your original post:
Code:
awk -F, '$2==&quot;MALE&quot;' /path/to/file
should do the trick.

Hope This Help
PH.
 
I got it.

Thanks all of you for answering my question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top