alignment

Hi,

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

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:

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

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

you can use 'cut' to separate each field into a file,

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:

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 this:)

  paste field1.txt field2.txt field3.txt xmlfields.txt > newfile.txt

Anything but pretty - but at least a point you may want to start from:

#! /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

With awk:

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?