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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I select fields from a file in KShell

Status
Not open for further replies.

Tison

Programmer
May 12, 1999
216
CH
I have the following text file and I want to create a shell script that will allow some processing on the first column depending on the value of the second column ie the script logic is like this ;
FOR EACH RECORD IN THE FILE
DO
LIST THE 2ND FIELD
IF 2ND FIELD IN (aaa,bcdf,EFEFET)
DO SOME SHELL PROCESSING USING THE FIRST FIELD
FI
DONE

The file is ;
02341 JOBA_23456
01231 AGDSFFDTB
63521 AFSGHD
01122 MJGDX_12345
 

Hello, Tison!

I have awk solution of your problem. Please, try this awk script:


BEGIN {

list = "ABC,AFSGHD,CBA" # list of reference values
split(list,item,",") # split list into items

}


{
for (i in item) {
if ($2 == item) { # test value of 2nd field

print $0 # do some action
}
}
}


You can use it or get idea for shell script.

Bye!

KP.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top