![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to read record by record from a file in unix | raoscb | UNIX for Dummies Questions & Answers | 1 | 05-16-2008 07:30 AM |
| Script to search a bad record in a file then put the record in the bad file | shilendrajadon | Shell Programming and Scripting | 2 | 12-28-2007 10:02 AM |
| Script to search a bad record in a file then put the record in the bad file | shilendrajadon | UNIX for Advanced & Expert Users | 1 | 12-28-2007 10:00 AM |
| splitting a record and adding a record to a file | rsolap | Shell Programming and Scripting | 1 | 08-13-2007 02:58 PM |
| Converting Tab delimited file to Comma delimited file in Unix | charan81 | Shell Programming and Scripting | 22 | 01-20-2006 09:24 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
help with agrep or awk delimited by |~| in a record
I have a file which contains 1 million records of the following format. Each field is delimited by a pipe tilda pipe "|~|" show below. I would like to print only one column ie the CARDDESC value.
for example here it says CARDDESC=A8T1. so anything after CARDDESC= and before |~|CARDTYPE is what I would like to get from this record and ignore everything else. In other words the value between CARDDESC= and |~|CARDTYPE which in the following example is A8T1 is what I need to know. Any help is really appreciated. if my question is not clear please let me know I will try to phrase it in a better way. Each filed is delimited by |~| that is for sure through out the file. so even if I can get CARDDESC=A8T1 I am happy. RECORD=NEW|~|NAME=SCO|~|MODEL=8220|~|WORK=ATM|~|SUBNET=ATM|~|SITE=RKS|~|REGION=NORTH A|~|COUNTRY=US|~ |SWITCH=FAX2|~|ETHERNET=1.4.1.1|~|LOOPB=N/A|~|SHELF=N/A|~|SLOT=12|~|SUBSLOT=N/A|~|STSCHAN=N/A|~|PORT=8|~|DS1SLOT=0|~|LINE=1|~|LPORTID=0|~|C ARDDESC=A8T1|~|CARDTYPE=0|~|ENCAPSULATION=N/A|~|BUNDLEID=0|~|PORTUSE=N/A|~|STATUS=T|~|MANAGED=YES|~|BILLINGID=N/A|~|CKTID=W86|~|CKTIP=1.0.0.1 7|~|PORTSERVICE=T1|~|SPEED=6|~|CHNLS=N/A|~|NX_Y=83| Last edited by knijjar; 04-06-2008 at 04:32 AM.. Reason: changing the title to include agrep or awk |
|
||||
|
Quote:
![]() |
|
||||
|
Quote:
![]() Then I recommend you to take a look at the library formats ( bibliography formats ) am sure you would come back and say much better ![]() |
|
||||
|
Works for me on Linux (I guess gawk, or actually mawk). matrixmadhan's solution is closer to the real McCoy so use that if it works for you. Or even, how about this. Code:
sed -n 's/.*|~|CARDDESC=//; T; s/|~|.*//p' matrixmadhan: agreed, I've seen much worse than this. I can also swear a lot louder than you have seen so far. (My colleagues can tell when I'm forced to use Windows.) Last edited by era; 04-06-2008 at 04:57 AM.. Reason: It's apparently mawk actually |
|
||||
|
Thanks ERA and MATRIXMADHAN.
/usr/local/bin/awk -F"CARDDESC=" '{ split($2, arr, "|"); print arr[1] }' t1 A8T1 now would you be kind enough try to explain what it really did. I have gone with what matrixmadhan recommended Peace !!! |
|
||||
|
I wouldnt agree with you more about the format. I hate it when people do that. and yes the filed is always going to be in the same column
which awk /usr/bin/awk awk -F '\|~\|' '{ print $20 }' RECORD awk: syntax error near line 1 awk: bailing out near line 1 /usr/local/bin/awk -F '\|~\|' '{ print $20 }' RECORD |CARDDESC=A8T1| /usr/local/bin/awk -F "|~|" '{print $20}' CIRCUITRECORD |CARDDESC=A8T1| same result The output contains a "pipe" symbol which is ok but can that be taken out from the output. I am happy with the results but just wondering. Thanks ERA in advance for your help |
![]() |
| Bookmarks |
| Tags |
| linux |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|