tr command giving wrong output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting tr command giving wrong output
# 1  
Old 05-07-2009
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.example.as.limits.ejb.LimitsServiceBean, SOURCE_METHOD=getLimitsList, MESSAGE=Failed to execute the
 CAS Limits Transaction via tfwk2.0 - due to SORResponseException: com.example.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.example.as.limits.ej
b.imitsServiceBean, SURE_MEHD=getimitsist, MESSGE=Failed to execute the S imits ransaction via tfwk2.0 - due to SRR
esponseException: com.example.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  
Old 05-07-2009
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  
Old 05-07-2009
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  
Old 05-07-2009
Code:
echo 'foo=bar, APPLICATION=ASComp, fred=baz' | sed 's/[ ]*APPLICATION=ASComp,//g'

# 5  
Old 05-07-2009
try this:

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


cheers,
Devaraj Takhellambam
# 6  
Old 05-07-2009
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.example.as.limits.ejb.LimitsServiceBean, MESSAGE=Failed to execute the
 CAS Limits Transaction via tfwk2.0 - due to SORResponseException: com.example.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  
Old 05-07-2009
Hammer & Screwdriver 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?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If && command giving wrong output

Hi All, I am trying to run a script which will search for 2 strings(stopped,started) in a text file and echo an output depending on below condition -bash-3.2$ cat trial1.txt v ggg f -bash-3.2$ cat trial1.sh VAR9=` grep 'stopped' /tmp/trial1.txt` VAR10=` grep 'started'... (4 Replies)
Discussion started by: srkmish
4 Replies

2. Shell Programming and Scripting

Number comparison in ksh on mac with -lt is giving wrong answer

I am trying to run following script in ksh on darwin 11.4.2: freeSpace=2469606195 spaceNeeded=200 ] && echo "no space" || echo "space available" ] && echo "no space" || echo "space available" "-lt" is giving wrong answer as "no space" Whereas '<' works fine. When I change the freespace... (4 Replies)
Discussion started by: sabitha
4 Replies

3. Shell Programming and Scripting

Grep command showing wrong output in Linux

Hi All I am trying to run a script in linux wherein i have a command like this grep ^prmAttunityUser= djpHewr2XFMAttunitySetup_ae1_tmp djpHewr2XFMAttunitySetup_ae1_tmp is a temporary file in which the user value is stored but this command in the script returns me balnk value whereas it has a... (4 Replies)
Discussion started by: vee_789
4 Replies

4. Shell Programming and Scripting

Wrong output in find command

Hi guys - I am trying a small script to tell me if there is a file that exists less than 1k. It should report ERROR, otherwise the check is good. I wrote this script down, however it never runs in the if/then statement. It always returns the echo ERROR. MYSIZE=$(find /home/student/dir1... (8 Replies)
Discussion started by: DallasT
8 Replies

5. UNIX for Advanced & Expert Users

xbindkeys giving wrong mapping information

Hello, I'm having a problem with xbindkeys giving the wrong mapping information, hence I can't get it work at all when trying new mappings from this machine. From another computer, I have some definitions for xbindkeys (made with xbindkeys-config). These key codes work correctly on this... (0 Replies)
Discussion started by: Narnie
0 Replies

6. Emergency UNIX and Linux Support

getting wrong output with AWK command!!!

i have a file which gets appended with 9 records daily and the file keeps growing from then...i use to store the previous day files count in a variable called oldfilecount and current files count as newfilecount.my requirement is that i need to start processing only the new records from the... (3 Replies)
Discussion started by: ganesh_248
3 Replies

7. Shell Programming and Scripting

Sort command giving wrong output

Hi all, I have a problem with sort command. i have a file which looks like this: "file1 1073 java/4 1073 java/180 1073 java/170 1073 java/176 1073 java/167 1073 java/40 1073 java/33 1073 java/136 28988 java/76 28988 java/73 28988 java/48 28988 java/26" and i want to sort... (8 Replies)
Discussion started by: usha rao
8 Replies

8. UNIX for Dummies Questions & Answers

AWK command giving wrong input

Hi all, I have a problem with qwk command. i have to check process status and for that i am using command prstat -mvL 1 1 and it gives me the entire output but when i use this command with awk like this: prstat -mvL 1 1 | awk -F" " '{print $1,$15}' to get first and 15th arguments. ... (3 Replies)
Discussion started by: usha rao
3 Replies

9. AIX

Shared memory giving wrong value

Hi , I am working on AIX 5.3 server.I have small program which stores the from database to a particaular shared memory.But while retreiving the valus from the same shared memory, i am getting wrong values. Please help..... (1 Reply)
Discussion started by: ajaysahoo
1 Replies

10. Shell Programming and Scripting

Script giving wrong results....

hi, I have this script which gives me the result... #! /usr/bin/sh set -x cd /home/managar a=1 while true do if then echo " File log.txt exists in this directory " exit 0 fi echo " File has not arrived yes..." sleep 3 let a=a+1 if then (1 Reply)
Discussion started by: mgirinath
1 Replies
Login or Register to Ask a Question