![]() |
|
|
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 |
| Sort command giving wrong output | usha rao | Shell Programming and Scripting | 8 | 04-07-2009 09:54 AM |
| AWK command giving wrong input | usha rao | UNIX for Dummies Questions & Answers | 3 | 04-01-2009 05:41 AM |
| Shared memory giving wrong value | ajaysahoo | AIX | 1 | 12-29-2008 06:42 AM |
| script not giving the desired output | Renjesh | Shell Programming and Scripting | 2 | 06-15-2008 04:58 AM |
| Script giving wrong results.... | mgirinath | Shell Programming and Scripting | 1 | 12-21-2005 09:45 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hi All, i have a file which have many fields delimited by ,(comma) now i have to show only few fields and not all. the sample text file looks like this: Code:
TYPE=SERVICEEVENT, TIMESTAMP=05/06/2009 11:01:40 PM, HOST=sppwa634, APPLICATION=ASComp, FUNCTION=LimitsService, SOU RCE=com.americanexpress.as.limits.ejb.LimitsServiceBean, SOURCE_METHOD=getLimitsList, MESSAGE=Failed to execute the CAS Limits Transaction via tfwk2.0 - due to SORResponseException: com.americanexpress.util.transfwk.exception.SORR esponseException : Timed out in receive for CorrelationID:ID:414d512053505057413633342020202049fb54cf2a1a5dd0 from: CASA:JMSWrapper : receive() :Timed out waiting for response for a correlation id : [ID:414d512053505057413633342020 202049fb54cf2a1a5dd0]QCFPoolName : [CASQCF] and ResponseQueueName : [MYCA_CAS_REPLY_QUEUE] Timeout[10000]for Card N umber : , SESSION_ID=b302cbd0-8d67a6e6-e3f371bd-d2561b0d, GUID=null, CARD_TYPE=null, ENTRY_URL=account, STATUS=fals e, TIME_TO_EXECUTE=36079, MARKET_IDENTIFIER=null, FAILED_SYSTEM=null, FAILURE_CATEGORY=null, FAIL_REASON_TEXT=null Form this file if i want to remove fields APPLICATION and SOURCE_METHOD both ending with a , i am using this line cat myfile | tr -d 'APPLICATION' 'SOURCE_METHOD' But this command is not working properly It is giving output like this: Code:
YE=SERVEEVE, MESM=05/06/2009 11:01:40 M, HS=sppwa634, =Somp, FU=imitsService, SURE=com.americanexpress.as.limits.ej b.imitsServiceBean, SURE_MEHD=getimitsist, MESSGE=Failed to execute the S imits ransaction via tfwk2.0 - due to SRR esponseException: com.americanexpress.util.transfwk.exception.SRResponseException : imed out in receive for orrelat ionD:D:414d512053505057413633342020202049fb54cf2a1a5dd0 from:S:JMSWrapper : receive() :imed out waiting for respons e for a correlation id : [D:414d512053505057413633342020202049fb54cf2a1a5dd0]QFoolame : [SQF] and ResponseQueueame : [MY_S_REY_QUEUE] imeout[10000]for ard umber : , SESS_D=b302cbd0-8d67a6e6-e3f371bd-d2561b0d, GUD=null, RD_YE=null, ERY_UR=account, SUS=false, ME__EXEUE=36079, MRKE_DEFER=null, FED_SYSEM=null, FURE_EGRY=null, F_RES_EX=null It is not removing the complete fields but removing some letters from every field. Please advice. Thanks |
|
||||
|
Hi Pludi,Thanks for your quick reply.
I got it. But i am not very comfortable with sed. Is there any way so that from that complete line i can remove some words for Eg: APPLICATION=ASComp, this complete field i want to remove similarly SOURCE_METHOD=getLimitsList, this field i want to remove?? Thanks |
|
||||
|
if you have Python, here's an alternative Code:
#!/usr/bin/env python
data=open("file").read().split(",")
for num,item in enumerate(data):
if "APPLICATION=ASComp" in item or "SOURCE_METHOD" in item:
data.pop(num)
print ','.join(data)
output: Code:
./test.py TYPE=SERVICEEVENT, TIMESTAMP=05/06/2009 11:01:40 PM, HOST=sppwa634, FUNCTION=LimitsService, SOU RCE=com.americanexpress.as.limits.ejb.LimitsServiceBean, MESSAGE=Failed to execute the CAS Limits Transaction via tfwk2.0 - due to SORResponseException: com.americanexpress.util.transfwk.exception.SORR esponseException : Timed out in receive for CorrelationID:ID:414d512053505057413633342020202049fb54cf2a1a5dd0 from: CASA:JMSWrapper : receive() :Timed out waiting for response for a correlation id : [ID:414d512053505057413633342020 202049fb54cf2a1a5dd0]QCFPoolName : [CASQCF] and ResponseQueueName : [MYCA_CAS_REPLY_QUEUE] Timeout[10000]for Card N umber : , SESSION_ID=b302cbd0-8d67a6e6-e3f371bd-d2561b0d, GUID=null, CARD_TYPE=null, ENTRY_URL=account, STATUS=fals e, TIME_TO_EXECUTE=36079, MARKET_IDENTIFIER=null, FAILED_SYSTEM=null, FAILURE_CATEGORY=null, FAIL_REASON_TEXT=null |
|
|||||
|
Code:
> tr "," "\n" <file19 | grep -v "APPLICATION" | tr "\n" "," Take my input file called file19, translate "," to new-line characters to put each parameter on its own line, grep to exclude any line with the word "APPLICATION", then change the new-line characters back to "," characters. Would this approach work for you? |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|