The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-07-2009
usha rao usha rao is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 70
Question tr command giving wrong output

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
  #2 (permalink)  
Old 05-07-2009
pludi's Avatar
pludi pludi is online now Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,962
tr doesn't replace words or fields, but characters. Example:
Code:
$ echo "abcdefghijklmnopqrstuvwxyz" | tr 'afik' 'AFIK'
AbcdeFghIjKlmnopqrstuvwxyz

The first letter in the first parameter is replaced with the first letter in the second parameter, the second letter in the first parameter is replaced with the second letter in the second parameter, ...
  #3 (permalink)  
Old 05-07-2009
usha rao usha rao is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 70
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
  #4 (permalink)  
Old 05-07-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131

Code:
echo 'foo=bar, APPLICATION=ASComp, fred=baz' | sed 's/[ ]*APPLICATION=ASComp,//g'

  #5 (permalink)  
Old 05-07-2009
devtakh devtakh is offline
Registered User
  
 

Join Date: Oct 2007
Location: Bangalore
Posts: 514
try this:


Code:
sed -e 's/APPLICATION[^,]*,//g' -e 's/SOURCE_MEATHOD[^,]*,//g' filename


cheers,
Devaraj Takhellambam
  #6 (permalink)  
Old 05-07-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,558
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

  #7 (permalink)  
Old 05-07-2009
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink another possible approach


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?
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:47 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0