![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| To cut entire column from a file and apend it to another file as another column | sakthifire | Shell Programming and Scripting | 4 | 06-25-2008 01:27 AM |
| Inserting a column in a file | dhanamurthy | Shell Programming and Scripting | 7 | 05-11-2008 07:29 AM |
| How to check Null values in a file column by column if columns are Not NULLs | Mandab | Shell Programming and Scripting | 7 | 03-15-2008 06:57 AM |
| Replace 10th column with a new column--- Terriblly hurry | ahmedwaseem2000 | Shell Programming and Scripting | 2 | 09-05-2005 10:10 PM |
| Splitting file using value in a column | gboom | Shell Programming and Scripting | 3 | 05-22-2005 08:07 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Code:
nawk '{ print ($3 == "~ZZ~VISTN" || $3 == "~ZZ~F159B") ? "passed" : "failed" }' myFile
|
|
#3
|
|||
|
|||
|
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 |
|
#4
|
||||
|
||||
|
Quote:
Quote:
..... | cut -d' ' -f3 |
|
#5
|
|||
|
|||
|
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 |
|
#6
|
||||
|
||||
|
well.... that's quite a different description.
try this: nawk -f is.awk myFile is.awk: Code:
BEGIN {
SEP=FS
RS=FS=""
}
$1 ~ /^ISA~/ { split($1, arr, SEP); print (arr[3] == "~ZZ~VISTN") ? "passed" : "failed" }
Last edited by vgersh99; 12-28-2005 at 04:37 PM. |
|
#7
|
|||
|
|||
|
Try this.
grep "~ZZ~" <data file> | nawk '{ print ($3=="~ZZ~VISTN") ? "passed":"failed" }' |
|||
| Google The UNIX and Linux Forums |