Visit Our UNIX and Linux User Community


Help me to command to output file format.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help me to command to output file format.
# 1  
Old 09-07-2010
Bug Help me to command to output file format.

Dear Master.

Help me to command to out put.

Ex log.
Code:
"<?xml version=""1.0"" encoding=""UTF-10"" ?><anova-test-bom>
  <txid>17251032659</txid>
  <authentication>
    <user>admin</user>
    <password>Amrduoi</password>
  </authentication>
  <destination>
    <msisdn>1111111</msisdn>
    <serviceid>1111111</serviceid>
  </destination>
  <originator>
    <mobi>123456724748274</msisdn>
  </originator>
  <message>
    <header>
      <timestamp>20100903154543</timestamp>
    </header>
    <sms>
      <msg>M</msg>
      <msgtype>E</msgtype>
      <encoding>0</encoding>
    </sms>
  </message>
  <startCallDateTime>20100903154543</startCallDateTime>
</anova-test-bom>"
"<?xml version=""1.0"" encoding=""UTF-10"" ?><anova-test-bom>
  <txid>17251032880</txid>
  <authentication>
    <user>admin</user>
    <password>Amrduoi</password>
  </authentication>
  <destination>
    <msisdn>1111111</msisdn>
    <serviceid>1111111</serviceid>
  </destination>
  <originator>
    <mobi>123456704470545</msisdn>
  </originator>
  <message>
    <header>
      <timestamp>20100903154545</timestamp>
    </header>
    <sms>
      <msg>M</msg>
      <msgtype>E</msgtype>
      <encoding>0</encoding>
    </sms>
  </message>
  <startCallDateTime>20100903154545</startCallDateTime>
</anova-test-bom>"
"<?xml version=""1.0"" encoding=""UTF-10"" ?><anova-test-bom>
  <txid>17251034752</txid>
  <authentication>
    <user>admin</user>
    <password>Amrduoi</password>
  </authentication>
  <destination>
    <msisdn>2222222</msisdn>
    <serviceid>2222222</serviceid>
  </destination>
  <originator>
    <mobi>123456744075149</msisdn>
  </originator>
  <message>
    <header>
      <timestamp>20100903154457</timestamp>
    </header>
    <sms>
      <msg></msg>
      <msgtype>E</msgtype>
      <encoding>0</encoding>
    </sms>
  </message>
  <startCallDateTime>20100903154457</startCallDateTime>
</anova-test-bom>"
"<?xml version=""1.0"" encoding=""UTF-10"" ?><anova-test-bom>
  <txid>17251037535</txid>
  <authentication>
    <user>admin</user>
    <password>Amrduoi</password>
  </authentication>
  <destination>
    <msisdn>3333333</msisdn>
    <serviceid>3333333</serviceid>
  </destination>
  <originator>
    <mobi>123456769969117</msisdn>
  </originator>
  <message>
    <header>
      <timestamp>20100903154521</timestamp>
    </header>
    <sms>
      <msg>D</msg>
      <msgtype>E</msgtype>
      <encoding>0</encoding>
    </sms>
  </message>
  <startCallDateTime>20100903154521</startCallDateTime>
</anova-test-bom>"
"<?xml version=""1.0"" encoding=""UTF-10"" ?><anova-test-bom>
  <txid>17251037655</txid>
  <authentication>
    <user>Amrdu</user>
    <password>1234Test</password>
  </authentication>
  <destination>
    <msisdn>4444444</msisdn>
    <serviceid>4444444</serviceid>
  </destination>
  <originator>
    <mobi>123456781540765</msisdn>
  </originator>
  <message>
    <header>
      <timestamp>20100903154522</timestamp>
    </header>
    <sms>
      <msg>R</msg>
      <msgtype>E</msgtype>
      <encoding>0</encoding>
    </sms>
  </message>
  <startCallDateTime>20100903154522</startCallDateTime>
</anova-test-bom>"
"<?xml version=""1.0"" encoding=""UTF-10"" ?><anova-test-bom>
  <txid>17251037848</txid>
  <authentication>
    <user>admin</user>
    <password>Amrduoi</password>
  </authentication>
  <destination>
    <msisdn>3333333</msisdn>
    <serviceid>3333333</serviceid>
  </destination>
  <originator>
    <mobi>123456768454593</msisdn>
  </originator>
  <message>
    <header>
      <timestamp>20100903154524</timestamp>
    </header>
    <sms>
      <msg>D</msg>
      <msgtype>E</msgtype>
      <encoding>0</encoding>
    </sms>
  </message>
  <startCallDateTime>20100903154524</startCallDateTime>
</anova-test-bom>"
"<?xml version=""1.0"" encoding=""UTF-10"" ?><anova-test-bom>
  <txid>17251039455</txid>
  <authentication>
    <user>Amrdu</user>
    <password>1234Test</password>
  </authentication>
  <destination>
    <msisdn>4444444</msisdn>
    <serviceid>5555555</serviceid>
  </destination>
  <originator>
    <mobi>123456714329185</msisdn>
  </originator>
  <message>
    <header>
      <timestamp>20100903154536</timestamp>
    </header>
    <sms>
      <msg>A</msg>
      <msgtype>E</msgtype>
      <encoding>0</encoding>
    </sms>
  </message>
  <startCallDateTime>20100903154536</startCallDateTime>
</anova-test-bom>"
"<?xml version=""1.0"" encoding=""UTF-10"" ?><anova-test-bom>
  <txid>17251040120</txid>
  <authentication>
    <user>admin</user>
    <password>Amrduoi</password>
  </authentication>
  <destination>
    <msisdn>1925532</msisdn>
    <serviceid>6666666</serviceid>
  </destination>
  <originator>
    <mobi>123456769505122</msisdn>
  </originator>
  <message>
    <header>
      <timestamp>20100903154540</timestamp>
    </header>
    <sms>
      <msg>A</msg>
      <msgtype>E</msgtype>
      <encoding>0</encoding>
    </sms>
  </message>
  <startCallDateTime>20100903154540</startCallDateTime>
</anova-test-bom>"
"<?xml version=""1.0"" encoding=""UTF-10"" ?><anova-test-bom>
  <txid>17251040593</txid>
  <authentication>
    <user>Amrdu</user>
    <password>1234Test</password>
  </authentication>
  <destination>
    <msisdn>4444444</msisdn>
    <serviceid>4444444</serviceid>
  </destination>
  <originator>
    <mobi>123456781540765</msisdn>
  </originator>
  <message>
    <header>
      <timestamp>20100903154544</timestamp>
    </header>
    <sms>
      <msg>R</msg>
      <msgtype>E</msgtype>
      <encoding>0</encoding>
    </sms>
  </message>
  <startCallDateTime>20100903154544</startCallDateTime>
</anova-test-bom>"
"<?xml version=""1.0"" encoding=""UTF-10"" ?><anova-test-bom>
  <txid>17251041433</txid>
  <authentication>
    <user>admin</user>
    <password>Amrduoi</password>
  </authentication>
  <destination>
    <msisdn>3333333</msisdn>
    <serviceid>3333333</serviceid>
  </destination>
  <originator>
    <mobi>1234567882795</msisdn>
  </originator>
  <message>
    <header>
      <timestamp>20100903154550</timestamp>
    </header>
    <sms>
      <msg>D</msg>
      <msgtype>E</msgtype>
      <encoding>0</encoding>
    </sms>
  </message>
  <startCallDateTime>20100903154550</startCallDateTime>
</anova-test-bom>"


I want out put format.

Code:
<msg>M</msg> <msgtype>E</msgtype> <encoding>0</encoding>
<msg>M</msg> <msgtype>E</msgtype> <encoding>0</encoding>
.
.
.
.
<msg>D</msg> <msgtype>E</msgtype> <encoding>0</encoding>

.


Help me please.
Thank YOU.

Moderator's Comments:
Mod Comment Please reduce the relevant files to some relevant part and post this part here (between CODE-tags, please!). Our users are not supposed to have to download anything from third-party-sources just to solve your problem. Thanks for your consideration.

Last edited by ooilinlove; 09-07-2010 at 12:39 PM..
# 2  
Old 09-07-2010
Try:
Code:
awk 's{s=s FS $1} /<msg>/{s=$1} /<encoding>/{print s; s=""}' file

# 3  
Old 09-07-2010
Code:
# grep -A 1 msg infile | sed 'N;N;s/\(.*\)\n\(.*\)\n\(.*\)/\1\2\3/;n;' | sed '/.*msg.*/!d;s/  */ /g;s/^.//'
<msg>M</msg> <msgtype>E</msgtype> <encoding>0</encoding>
<msg>M</msg> <msgtype>E</msgtype> <encoding>0</encoding>
<msg></msg> <msgtype>E</msgtype> <encoding>0</encoding>
<msg>D</msg> <msgtype>E</msgtype> <encoding>0</encoding>
<msg>R</msg> <msgtype>E</msgtype> <encoding>0</encoding>
<msg>D</msg> <msgtype>E</msgtype> <encoding>0</encoding>
<msg>A</msg> <msgtype>E</msgtype> <encoding>0</encoding>
<msg>A</msg> <msgtype>E</msgtype> <encoding>0</encoding>
<msg>R</msg> <msgtype>E</msgtype> <encoding>0</encoding>
<msg>D</msg> <msgtype>E</msgtype> <encoding>0</encoding>


Previous Thread | Next Thread
Test Your Knowledge in Computers #408
Difficulty: Medium
The Cygwin distribution contains thousands of packages from the Open Source world including most GNU tools, many BSD tools, an X server and a full set of X applications.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to format output of command?

Hi how do you change the format of the output of ls -lt -c -R $HOME | sed /^total/d From: /home/pikamon/Desktop: -rwxr-xr-x 1 pikamon pikamon 35 Sep 18 14:25 fileModified.sh -rwxr-xr-x 1 pikamon pikamon 87 Sep 18 14:25 fileModified.sh~ /home/darksky21/Downloads: -rwxrw-rw- 1 pikamon... (5 Replies)
Discussion started by: pikamon
5 Replies

2. Shell Programming and Scripting

Grep command output in tabular format

I have a grep command script which works fine and give the correct results but i wanted the output to be displayed in tabular format ? Is it possible to display the output in tabular format and as well direct them to some file. main script : #!/usr/bin/bash Start_Time=`date '+%m%d%y... (1 Reply)
Discussion started by: Optimus81
1 Replies

3. Shell Programming and Scripting

UNIX command output in csv format

I'm just wondering is there any way to capture the output of a unix command in a csv format. df -h gives the result of filesystem,free space,Used space, use %,mounted on. Is there a way to capture the command output and format it as comma sparated or fixed length file. (3 Replies)
Discussion started by: anita81
3 Replies

4. UNIX for Dummies Questions & Answers

UNIX command output format

how can I get the df -h command output into excel format or csv file. df -k | tr -s " " | sed 's/ /, /g' | sed '1 s/, / /g' | column -t df -h | column -t I have tried as above but the format is not right. I'm not able to load the format into a excel or a table. ... (2 Replies)
Discussion started by: anita81
2 Replies

5. Shell Programming and Scripting

Format Top and prstat command output

need help with formatting output of command top and prstat. My requirment is to remove few columns and display remaining . But when i used awk to do that the output seems to be have gone vague, mixing the column values. After using awk to print particular column the output seems to have lost... (1 Reply)
Discussion started by: NarayanaPrakash
1 Replies

6. Shell Programming and Scripting

Format output in AWK command

hi Friends , I have a file as below s.txt 1~2~~4 2~6~~7 3~8~~9 t.txt 1~2~~4 2~5~8~7 3~8~~7 header for both files is common (2 Replies)
Discussion started by: i150371485
2 Replies

7. Shell Programming and Scripting

Format output from command from variables

Hi , I have below command to that outputs from variables.. command: echo $INSTANCE $DATAB $status $TSLastBackup| awk '{printf("%-8s %-8s \t \n",$1,$2,$3,$4)}' | tee $LOGF the ouput is now: INSTANCE DATABSE BACKUP_STATUS BACKUPTIMESTAMP ------- -------- -------- ... (1 Reply)
Discussion started by: db2_usd
1 Replies

8. Shell Programming and Scripting

shell script to format command output

Hello team, I am running below command which is giving following output. bash-3.00$ ps -eo pid,pcpu,args | sort +1n | grep -i java 12 0.0 grep -i java 8804 0.0 /opt/app/ccr/home/ccr/WebSphere/AppServer/java/bin/sparcv9/java -XX:+UnlockDiag 9241 0.0... (7 Replies)
Discussion started by: coolguyamy
7 Replies

9. Shell Programming and Scripting

Dynamic output file generation using a input text file with predefined output format

Hi, I have two files , one file with data file with attributes that need to be sent to another file to generate a predefined format. Example: File.txt AP|{SSHA}VEEg42CNCghUnGhCVg== APVG3|{SSHA}XK|"password" AP3|{SSHA}XK|"This is test" .... etc --------- test.sh has... (1 Reply)
Discussion started by: hudson03051nh
1 Replies

10. Shell Programming and Scripting

Format Output with AWK command

Hi - I have a file with contents as below. 12.1 a.txt 12.1 b.txt 12.1 c.txt 13.2 a.txt 13.2 d.txt 14.3 f.txt 15.4 a.txt 15.4 b.txt 15.4 z.txt I need to print the contents like this. 12.1 a.txt <&nbsp><&nbsp><&nbsp>b.txt <&nbsp><&nbsp><&nbsp>c.txt (7 Replies)
Discussion started by: guruparan18
7 Replies

Featured Tech Videos