cut the third column from a file

I have a text file which has the following data. There can be more lines in the file. But, I am only interested in these two lines which has ~ZZ~VISTN and ~ZZ~F159B segments.

ISA~00~ ~00~ ~ZZ~VISTN ~ZZ~U1CAD ~051227~183
7~U~00200~000011258~0~P~<

ISA~00~ ~00~ ~ZZ~F159B ~ZZ~U1CAD ~051227~191
3~U~00200~000011467~0~P~<

I am to get this third column from the file and store it in some variable and then compare if it is "~ZZ~VISTN" it is passed otherwise it is fail.

In oder to get the third column, I am using the cut command along with grep but it does not seems to be working and it is returning the whole line.

grep -n ~ZZ~ success.lst | cut -f3 > pass.txt.

The desired result is "~ZZ~VISTN and ~ZZ~F159B but it is returning the whole data. Maybe I am missing something here. Please advise.

Regards,
Inder

nawk '{ print ($3 == "~ZZ~VISTN" || $3 == "~ZZ~F159B") ? "passed" : "failed" }' myFile

Hi Vgersh99,

Thanks much for the reply!!

The solution you have provided in your post did not really work.

When I run the command it is returning lots of rows with passed and failed, when there are two rows with ~ZZ~, the data I am interested in.

If I want to grep the value of third column and store it in some variable, How I can achieve that. As I said, when I tried cut it did not gave me the desired results.

Regards,
Inder

that's kin of strange - works just fine here. If you want you can post your sample file.

assuming your fields are 'space' separated:
..... | cut -d' ' -f3

Hi Vgersh99,

Thanks for the prompt reply!!!

This is the data file I am talking about.

ISA~00~ ~00~ ~ZZ~VISTN ~ZZ~U1CAD ~051227~183
7~U~00200~000011258~0~P~<
GS~FA~EE05J~U1CAD~051227~1831~000011258~X~002002
ST~997~0001
AK1~SH~247
AK2~856~2470001
AK5~A
AK2~856~2470002
AK5~A
AK9~A~2~2~2
SE~8~0001
GE~1~000011258
IEA~00001~000011258

ISA~00~ ~00~ ~ZZ~F159B ~ZZ~U1CAD ~051227~191
3~U~00200~000011467~0~P~<
GS~FA~AF52M~U1CAD~051227~1913~000011467~X~002002
ST~997~0001
AK1~SH~53
AK2~856~530001
AK5~A
AK9~A~1~1~1
SE~6~0001
GE~1~000011467
IEA~00001~000011467

And I am interested in every first line which starts with ISA, what I am trying to do is to get the value of third field which is ~ZZ~F159B and ~ZZ~VISTN, If it is ~ZZ~VISTN then it is PASS and if it is ~ZZ~F159B then it is fail.

I tried the cut command also which you send and that also did not work for me. I believe that I am doing something wrong.

Anyways, Thanks much for your help!!!

Regards,
Inder

well.... that's quite a different description.
try this:

nawk -f is.awk myFile

is.awk:

BEGIN {
  SEP=FS
  RS=FS=""
}
$1 ~ /^ISA~/ { split($1, arr, SEP); print (arr[3] == "~ZZ~VISTN") ? "passed" : "failed" }

Try this.
grep "~ZZ~" <data file> | nawk '{ print ($3=="~ZZ~VISTN") ? "passed":"failed" }'

don't need 'grep'.
also the requirement was

Thanks much Vgersh and Rancha!!!

I really apprecitate your help.

Regards,
Inder