alignment


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting alignment
# 1  
Old 09-29-2009
alignment

Hi,

I am having a file with with format.
however, for longer xml, the xml code has been truncated like this.

Code:
F1    |######################                  |String1        |<XML><REQ><MSGTYPE>DBDIRECT</MSGTYPE><SYNC>0</SYNC><CLIENT>C11</CLIENT>NAME=MYNAME|JOB=MYJOB|
      |                                        |               |LOCATION=MYLOC|COUNTRY=MYCON|TECHNOLOGY
      |                                        |               |=XML</REQ></XML>

I want to make complete xml string.

output:
Code:
F1    |######################                  |String1        |<XML><REQ><MSGTYPE>DBDIRECT</MSGTYPE><SYNC>0</SYNC><CLIENT>C11</CLIENT>NAME=MYNAME|JOB=MYJOB|LOCATION=MYLOC|COUNTRY=MYCON|TECHNOLOGY=XML</REQ></XML>

because, I am using below command to fetch the xml code from the above file

Code:
sed -n '/<XML>.*<\/XML>/ s/.*\(<XML>.*<\/XML>\).*/\1/p' file

and it is failing for the above records.

is it possible to format the file like above, or is there way to get only xml code from the file?

note: I can't use awk since it exceeds the record limit and i dont have gawk.

Thanks
# 2  
Old 09-29-2009
you can use 'cut' to separate each field into a file,
Code:
cut -f1 -d'|' in > field1.txt
cut -f2 -d'|' in > field2.txt
cut -f3 -d'|' in > field3.txt
cut -f4-99 -d'|' in > xmlfields.txt

then loop through 'xmlfields.txt' to join the rows which should be on one line, something like:
Code:
touch fmtxml.txt
while read line
do
  COUNT_CLOSING_TAG=`echo $line|grep -c "</XML>"`
  if [ $COUNT_CLOSING_TAG -eq 0 ]
  then
    echo $line | tr -d "\n"  >> fmtxml.txt
  else
    echo $line >> fmtxml.txt
  fi
done < xmlfields.txt

then paste all the files back together (check the syntax on thisSmilie
Code:
  paste field1.txt field2.txt field3.txt xmlfields.txt > newfile.txt


Last edited by varontron; 09-29-2009 at 02:58 PM..
# 3  
Old 09-29-2009
Anything but pretty - but at least a point you may want to start from:

Code:
#! /bin/bash

sed 's/      |                                        |               |//g' -i file.in
BUFFER=''
cat file.in | \
while read LINE
do
  if [ -n "$( echo $LINE | grep '#######' | grep '</XML>' )" ]
  then
    echo "$LINE" >> file.out
  else
    BUFFER=$( echo "$BUFFER$LINE" )
    if [ -n "$( echo $BUFFER | grep '#######' | grep '</XML>' )" ]
    then
      echo "$BUFFER" >> file.out
      BUFFER=''
    fi
  fi
done

exit 0

# 4  
Old 09-29-2009
With awk:

Code:
awk -F" +[|]" '{printf $0;getline;printf $4;getline;printf $4}' file



---------- Post updated at 08:14 PM ---------- Previous update was at 08:06 PM ----------

ooops. Just realised awk was excluded from OP's available tools. But are you sure you can't use awk for this?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help with awk alignment

Dear All, I am in the beginning stage of learning shell scripting and preparing shell script on my own now. I would like to get help from fellow mates here. As I am trying to take O/P with space included from I/P table. Kindly guide me to align given I/P table as Expected O/P. ... (5 Replies)
Discussion started by: Raja007
5 Replies

2. Shell Programming and Scripting

Row alignment

*1 flash read test(*do_test1*) PASS *2 xxxxxxxxxxx flash write test(*do_test2) FAIL ------>xxxxx *1 flash read test(*do_test1*) PASS *2 xxxxxxxxxxx flash write test(*do_test2) FAIL ------>xxxxx I want pass and Fail to be aligned if each line uses printf or echo to print, is... (5 Replies)
Discussion started by: yanglei_fage
5 Replies

3. HP-UX

HP-UX text alignment

HI all, I tried to edit my files using HP-UX but my output tends to not align when I add another character in the files to edit my files i used the command is as follow chmod +w filename vi filename Help, :eek: (1 Reply)
Discussion started by: jasonhpwong
1 Replies

4. Shell Programming and Scripting

Output alignment problem

Hi Gurus, This is my raw data. How would I able to format this output into a better alignment? /dev/vg00/lvol5 /home 0.12 GB 0.02 GB 0.10 GB 19% /dev/vg00/misc /misc 28.43 GB 4.92 GB 23.51 GB 17% /dev/vg00/lvol6 /opt 8.25 GB 5.43 GB 2.82 GB 65% /dev/vgsap/ora10264 ... (10 Replies)
Discussion started by: superHonda123
10 Replies

5. Shell Programming and Scripting

Formatting output alignment

Hi Gurus, I've the following output from my scripting as shown below. 0.48 GB 0.29 GB 0.19 GB 60% 0.48 GB 0.29 GB 0.19 GB 60% 228.90 GB 89.47 GB 139.42 GB 39% 228.76 GB 72.37 GB 156.39 GB 31% Is it possible to format this output into a proper... (16 Replies)
Discussion started by: superHonda123
16 Replies

6. Shell Programming and Scripting

Adding sequences to alignment

I would like to add the following references at the very beggining of all my files: Thus, the resulting file should look like this: Any help will be very much appreciated (6 Replies)
Discussion started by: Xterra
6 Replies

7. UNIX for Dummies Questions & Answers

VI paste out of alignment

We have a guy at work who is trying to copy and paste from one file to another using vi and highlighting the code to copy with a mouse. Source file: xyz 123 abc 999 zyx 321 cba 999 xyz 123 abc 999 But when he pastes it he gets (I put the underlines in to show... (4 Replies)
Discussion started by: dlam
4 Replies

8. Shell Programming and Scripting

alignment of variable

Dear Champs, i have a file let a.txt having value number text 00 123 012 145 456 ...etc i need number and text column vales should right align ??? how can i achive this ??? NOTE number is of max 3 char and text can take max 7 char...so if any records are less than above lengths... (2 Replies)
Discussion started by: manas_ranjan
2 Replies

9. UNIX for Dummies Questions & Answers

Column Alignment

I copied a word file to my Unix directory, How do I line up my columns to the file I copied over? (3 Replies)
Discussion started by: nikncha
3 Replies
Login or Register to Ask a Question