LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-23-2010, 04:29 PM   #1
hugh86
LQ Newbie
 
Registered: Oct 2010
Posts: 9

Rep: Reputation: 0
using SED or AWK to cut data from a file, between certain characters


Hello,

Just found this website and have had a look around and seems that i have come to the right place.

I would like to create a .ksh script which cuts certain data from a document. I have tried to use SED and AWK and piping but its been some time since i have operated on Linux and my memory is patchy.

Any help would be greatly appreciated


Hugh
 
Old 10-23-2010, 05:14 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 614Reputation: 614Reputation: 614Reputation: 614Reputation: 614Reputation: 614
Use grep and its --only-matching option? You haven't provided examples of what you have and what you want to get back..
 
Old 10-23-2010, 06:05 PM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by hugh86 View Post
I have tried to use SED and AWK and piping but its been some time since i have operated on Linux and my memory is patchy.
well, if you forgot a maths formula, you look it up in your text book right? same with using sed/awk (and practically anything). Look it up on how to use it again. first off, start with man pages. then show us what you have tried and where you got stuck.
 
Old 10-23-2010, 06:50 PM   #4
hugh86
LQ Newbie
 
Registered: Oct 2010
Posts: 9

Original Poster
Rep: Reputation: 0
it is something i am doing at work but wanted to get a head start before monday... I would like the script to open a file that user wants.. cut certain information from that document and write it to another file.

Unfortunaley i cannot provide an input and output just yet... potentially tomorrow.

Code:
 sed 's/^[ \t]*//' Statement.xml | awk '/objectName|fieldValue|fieldName/' | less
i have done the above which works.. it alligns all the information to the left making it easier on the eye intially then cuts all the information matching objectName etc.. however i now need the script to ask the user what file they wish to open.

i have looked onlne at how to write to another file but i havent been successful yet.

Thankyou for gettin back to me.

Last edited by hugh86; 10-23-2010 at 06:51 PM.
 
Old 10-23-2010, 08:14 PM   #5
ee437
LQ Newbie
 
Registered: Oct 2010
Location: Wisconsin, USA
Distribution: Slackware
Posts: 12

Rep: Reputation: 4
For the files, there are two ways that i can think of.

first, you can run the script with an input file and output file on the command line:

sh <script>.ksh input.fil output.fil

in your script, $1=input.fil, $2=output.fil

or, get input with read, or, use read -p, like this:

read -p " Enter the input filename: " INFILE

to access INFILE, you need to use $INFILE.

If this looks really foreign to you, there is a HOW-TO for bash scripting that might be really helpful.

i hope that helps.
 
1 members found this post helpful.
Old 10-23-2010, 10:03 PM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
there's no need to use sed. Just awk will do. And since you are dealing with xml (i assume), i think your requirement would not be that simple. Anyway, post whatever input you may have ,and show desired output as needed.
 
Old 10-24-2010, 11:31 AM   #7
hugh86
LQ Newbie
 
Registered: Oct 2010
Posts: 9

Original Poster
Rep: Reputation: 0
Hi again,

I have got the input file which is a .txt.

Code:
 


 COMPONENT:     3053                 INSERT  RC:        LL ID:NULL
 L2field
   *docRequestNo    :2010-10-22-11.57.22.903813
   *l1SeqNo         :1
   *l2SeqNo         :1
   *l3SeqNo         :4
   *prtFldId        :13
    prtFldName      :salutationName
    prtFldValue     :N
    prtFldNo        :1519

 COMPONENT:     3053                 INSERT  RC:        LL ID:NULL
 L2field
   *docRequestNo    :2010-10-22-11.57.22.903813
   *l1SeqNo         :1
   *l2SeqNo         :1
   *l3SeqNo         :4
   *prtFldId        :14
  N
    prtFldNo        :1093

 COMPONENT:     3053                 INSERT  RC:        LL ID:NULL
 L2field
   *docRequestNo    :2010-10-22-11.57.22.903813
   *l1SeqNo         :1
   *l2SeqNo         :1
   *l3SeqNo         :4
   *prtFldId        :15
    prtFldName      :title
    prtFldValue     :MR
    prtFldNo        :1083

 COMPONENT:     3053                 INSERT  RC:        LL ID:NULL
 L2field
   *docRequestNo    :2010-10-22-11.57.22.903813
   *l1SeqNo         :1
   *l2SeqNo         :1
   *l3SeqNo         :4
    prtFldNo        :1085

 COMPONENT:     3053                 INSERT  RC:        LL ID:NULL
 L2field
   *docRequestNo    :2010-10-22-11.57.22.903813
   *l1SeqNo         :1
   *l2SeqNo         :1
    prtFldNo        :1086

 COMPONENT:     3053                 INSERT  RC:        LL ID:NULL
 L2field
   *docRequestNo    :2010-10-22-11.57.22.903813
   *l1SeqNo         :1
   *l2SeqNo         :1
   *l3SeqNo         :4
   *prtFldId        :18
    prtFldName      :gender
    prtFldValue     :M
    prtFldNo        :1532

 

 COMPONENT:     3053                 INSERT  RC:        LL ID:NULL
 L2field
   *docRequestNo    :2010-10-22-11.57.22.903813
   *l1SeqNo         :1
   *l2SeqNo         :1
   *l3SeqNo         :5
   *prtFldId        :11
    prtFldName      :lifetimeSlaAmount
    prtFldValue     :1800000
    prtFldNo        :1517

 COMPONENT:     3053                 INSERT  RC:        LL ID:NULL
 L2field
   *docRequestNo    :2010-10-22-11.57.22.903813
   *l1SeqNo         :1
   *l2SeqNo         :1
   *l3SeqNo         :5
   *prtFldId        :12
    prtFldName      :slaAmountTaxYear
    prtFldValue     :2010
    prtFldNo        :1518

 COMPONENT:     3053                 INSERT  RC:        LL ID:NULL
 L2field
   *docRequestNo    :2010-10-22-11.57.22.903813
   *l1SeqNo         :1
   *l2SeqNo         :1
   *l3SeqNo         :5
   *prtFldId        :13
    prtFldName      :salutationName
    prtFldValue     :N
    prtFldNo        :1519

 COMPONENT:     3053                 INSERT  RC:        LL ID:NULL
 L2field
   *docRequestNo    :2010-10-22-11.57.22.903813
   *l1SeqNo         :1
   *l2SeqNo         :1
   *l3SeqNo         :5
   *prtFldId        :14
    prtFldNo        :1093

 COMPONENT:     3053                 INSERT  RC:        LL ID:NULL
 L2field
   *docRequestNo    :2010-10-22-11.57.22.903813
   *l1SeqNo         :1
   *l2SeqNo         :1
   *l3SeqNo         :5
   *prtFldId        :15
    prtFldName      :title
    prtFldValue     :MR
    prtFldNo        :1083

 COMPONENT:     3053                 INSERT  RC:        LL ID:NULL
 L2field
   *docRequestNo    :2010-10-22-11.57.22.903813
   *l1SeqNo         :1
   *l2SeqNo         :1
   *l3SeqNo         :5
   *prtFldId        :16
    prtFldName      :forename
    prtFldNo        :1085

 COMPONENT:     3053                 INSERT  RC:        LL ID:NULL
 L2field
   *docRequestNo    :2010-10-22-11.57.22.903813
   *l1SeqNo         :1
   *l2SeqNo         :1
   *l3SeqNo         :5
    prtFldNo        :1086

 COMPONENT:     3053                 INSERT  RC:        LL ID:NULL
 L2field
   *docRequestNo    :2010-10-22-11.57.22.903813
   *l1SeqNo         :1
   *l2SeqNo         :1
   *l3SeqNo         :5
   *prtFldId        :18
    prtFldName      :gender
    prtFldValue     :M
    prtFldNo        :1532

 COMPONENT:     3053                 INSERT  RC:        LL ID:NULL
 L2field
   *docRequestNo    :2010-10-22-11.57.22.903813
   *l1SeqNo         :1
   *l2SeqNo         :1
   *l3SeqNo         :5
   *prtFldId        :19
    prtFldName      :initials
 #  prtFldValue     :
    prtFldNo        :1084

 COMPONENT:     3053                 INSERT  RC:        LL ID:NULL
 L2field
   *docRequestNo    :2010-10-22-11.57.22.903813
   *l1SeqNo         :1
   *l2SeqNo         :1
   *l3SeqNo         :5
   *prtFldId        :20
    prtFldName      :organisationInd
    prtFldValue     :N
    prtFldNo        :1520

 Error number : 22127  Severity : Error         Destination : DIO
 Send commit was done due to SAPMSEND
 =============================================================================
 Get message ID             TrcId= 0000  BLP level =  0000
  RefToMsg=                        0024
  PARTY      :
 Thunderhead
  PARAMETERS :
 FN=S0231263
 -----------------------------------------------------------------------------
 Message preparation starts TrcId= 0001  BLP level =  0000
  Triggered by: Ruleset 114025      30
  To party   : Thunderhead
 Document Building started  TrcId= 0002  BLP level =  0000  DBID = LL
  SERVICE    : Thunderhead                DOCUMENT   :GenDocRequest
  Key fields  :
   *DOC REQUEST NO  :2010-10-22-11.57.22.903813
 Internal DIO :
 Q1105B00000062FH00003047000000000000000000000000002010-10-22-11.57.22.903813;
 Document Building    ended TrcId= 0002  BLP level =  0000
 Message preparation  ended TrcId= 0001 rc= 0000  ERROR=0000  BLP level = 0000
 -----------------------------------------------------------------------------
 Message Sending started RefToMsg= 0001  BLP level =  0000
  CHANNEL    : THCH1
  SYNCHRONOUS: N                          Now        :N
  TIMEOUT    : 00003000                   EXIT NAME  :
  Reply QNAME:
  MSG ID     :                            CORREL ID  :
  Out QNAME  :
  MQ Manager :
  SERVER NAME:
  DB ID      :                            LOGON SESS :
  USER ID    : LV20073                    PASSWORD   :
  SYS USER ID:                            PASSWORD   :
  SOAP ACTION:
  PROXY      :
  PORT       :
 Sending XML          :
 <document> <docRequestID>2010-10-22-11.57.22.903813</docRequestID><docStylesh
 eet>Thunderhead</docStylesheet><requestType>claim</requestType><level0Object>
  <objectType>transaction</objectType><objectID>900</objectID><objectSeq>1</ob
 jectSeq><level1Object> <objectType>lifelite</objectType><objectID>901</object
 ID><objectSeq>1</objectSeq><level2Object> <objectType>documentHeader</objectT
 ype><objectID>100</objectID><objectSeq>1</objectSeq><objectField> <fieldID>15
 00</fieldID><fieldName>transactionType</fieldName><fieldValue>6</fieldValue><
 /objectField><objectField> <fieldID>1501</fieldID><fieldName>lifeliteReferenc
 e</fieldName><fieldValue>000231263</fieldValue></objectField><objectField> <f
 ieldID>1502</fieldID><fieldName>requestorUserid</fieldName><fieldValue>LV2007
 3</fieldValue></objectField><objectField> <fieldID>1503</fieldID><fieldName>r
 equestDate</fieldName><fieldValue>2010-10-22</fieldValue></objectField><objec
 tField> <fieldID>1504</fieldID><fieldName>requestTime</fieldName><fieldValue>
 6</fieldValue></objectField><objectField> <fieldID>1505</fieldID><fieldName>b
 usProcess</fieldName><fieldValue>LLP0101</fieldValue></objectField><objectFie
 ld> <fieldID>1506</fieldID><fieldName>insert</fieldName><fieldValue>N</fieldV
 alue></objectField><objectField> <fieldID>1507</fieldID><fieldName>adviserNam
 e</fieldName><fieldValue>PHIL</fieldValue></objectField></level2Object
 ><level2Object> <objectType>recipient</objectType><objectID>110</objectID><ob
 jectSeq>2</objectSeq><objectField> <fieldID>1510</fieldID><fieldName>rcpntPar
 tyId</fieldName><fieldValue>7510134</fieldValue></objectField><objectField> <
 fieldID>1511</fieldID><fieldName>companyCode</fieldName><fieldValue>LVG</fiel
 dValue></objectField></level2Object><level2Object> <objectType>claim</objectT
 ype><objectID>120</objectID><objectSeq>3</objectSeq><objectField> <fieldID>11
 07</fieldID><fieldName>claimRef</fieldName><fieldValue>V1058036</fieldValue><
 /objectField><objectField> <fieldID>1108</fieldID><fieldName>totalClaimAmount
 </fieldName><fieldValue>10000.00</fieldValue></objectField><objectField> <fie
 ldID>1109</fieldID><fieldName>totalGroupClaimAmt</fieldName><fieldValue>10000
 .00</fieldValue></objectField><objectField> <fieldID>1533</fieldID><fieldName
 >totalFundAmt</fieldName><fieldValue>100000.00</fieldValue></objectField><obj
 ectField> <fieldID>1110</fieldID><fieldName>trivialityInd</fieldName><fieldVa
 lue>N</fieldValue></objectField><objectField> <fieldID>1111</fieldID><fieldNa
 me>reducedPensionAmt</fieldName><fieldValue>3750.00</fieldValue></objectField
 ><objectField> <fieldID>1112</fieldID><fieldName>firstPaymentDate</fieldName>
 <fieldValue>2010-11-19</fieldValue></objectField><objectField> <fieldID>1113<
 /fieldID><fieldName>paymentType</fieldName><fieldValue>IN ADVANCE</fieldValue
 ></objectField><objectField> <fieldID>1114</fieldID><fieldName>paymentInterva
 l</fieldName><fieldValue>QUARTERLY</fieldValue></objectField><objectField> <f
 ieldID>1115</fieldID><fieldName>lumpSumAmt</fieldName><fieldValue>25000.00</f
 ieldValue></objectField><objectField> <fieldID>1116</fieldID><fieldName>resid
 ualSum</fieldName><fieldValue>75000.00</fieldValue></objectField><objectField
 > <fieldID>1117</fieldID><fieldName>slaPerc</fieldName><fieldValue>0.000</fie
 ldValue></objectField><objectField> <fieldID>1118</fieldID><fieldName>jointLi
 fePercentage</fieldName><fieldValue>0.00</fieldValue></objectField><objectFie

 Message Sending ended   RefToMsg= 0001 rc= 0                 BLP level = 0000
When prompted, the user should point to this file... the script should then extract the XML only. Creating the following as the desired output:

Code:
 ld><objectField> <fieldID>1118</fieldID><fieldName>jointLi
 fePercentage</fieldName><fieldValue>0.00</fieldValue></objectField><objectFie
 ld> <fieldID>1531</fieldID><fieldName>manualActionInd</fieldName><fieldValue>
 N</fieldValue></objectField><level3Object> <objectType>plan</objectType><obje
 ctID>121</objectID><objectSeq>1</objectSeq><objectField> <fieldID>1534</field
 ID><fieldName>planRef</fieldName><fieldValue>P00029867B</fieldValue></objectF
 ield><level4Object> <objectType>policy</objectType><objectID>122</objectID><o
 bjectSeq>1</objectSeq><objectField> <fieldID>1016</fieldID><fieldName>prodNam
 e</fieldName><fieldValue>FLEXIBLE PERSONAL PENSION PLAN</fieldValue></objectF
 ield><objectField> <fieldID>1015</fieldID><fieldName>tableId</fieldName><fiel
 dValue>105A</fieldValue></objectField><objectField> <fieldID>1521</fieldID><f
 ieldName>policyId</fieldName><fieldValue>P00029867B01</fieldValue></objectFie
 ld><objectField> <fieldID>1522</fieldID><fieldName>policyNumber</fieldName><f
 ieldValue>P00029867B01</fieldValue></objectField><objectField> <fieldID>1534<
 /fieldID><fieldName>planRef</fieldName><fieldValue>P00029867B</fieldValue></o
 bjectField><objectField> <fieldID>1112</fieldID><fieldName>earlyRetirementDat
 e</fieldName><fieldValue>2010-11-19</fieldValue></objectField><objectField> <
 fieldID>1523</fieldID><fieldName>retirementDate</fieldName><fieldValue>2010-1
 1-19</fieldValue></objectField><objectField> <fieldID>1524</fieldID><fieldNam
 e>retirementAge</fieldName><fieldValue>0</fieldValue></objectField><objectFie
 ld> <fieldID>1525</fieldID><fieldName>pensionAmount</fieldName><fieldValue>10
 0000.00</fieldValue></objectField><objectField> <fieldID>1118</fieldID><field
 Name>jointAnnuityPerc</fieldName><fieldValue>0.00</fieldValue></objectField><
 objectField> <fieldID>1526</fieldID><fieldName>guaranteePeriod</fieldName><fi
 eldValue>5</fieldValue></objectField><objectField> <fieldID>1527</fieldID><fi
 eldName>escalationRate</fieldName><fieldValue>11.00</fieldValue></objectField
 ><objectField> <fieldID>1530</fieldID><fieldName>pensionType</fieldName><fiel
 dValue>P</fieldValue></objectField><level5Object> <objectType>interests</obje
 ctType><objectID>123</objectID><objectSeq>1</objectSeq><objectField> <fieldID
 >1528</fieldID><fieldName>partyInterestType</fieldName><fieldValue>BEN</field
 Value></objectField><objectField> <fieldID>1529</fieldID><fieldName>partyId</
 fieldName><fieldValue>7510135</fieldValue></objectField></level5Object><level
 5Object> <objectType>interests</objectType><objectID>123</objectID><objectSeq
 >2</objectSeq><objectField> <fieldID>1528</fieldID><fieldName>partyInterestTy
 pe</fieldName><fieldValue>LIN</fieldValue></objectField><objectField> <fieldI
 D>1529</fieldID><fieldName>partyId</fieldName><fieldValue>7510134</fieldValue
 ></objectField></level5Object><level5Object> <objectType>interests</objectTyp
 e><objectID>123</objectID><objectSeq>3</objectSeq><objectField> <fieldID>1528
 </fieldID><fieldName>partyInterestType</fieldName><fieldValue>PRO</fieldValue
 ></objectField><objectField> <fieldID>1529</fieldID><fieldName>partyId</field
 Name><fieldValue>7510134</fieldValue></objectField></level5Object></level4Obj
 ect><level4Object> <objectType>policy</objectType><objectID>122</objectID><ob
 jectSeq>2</objectSeq><objectField> <fieldID>1016</fieldID><fieldName>prodName
 </fieldName><fieldValue>FLEXIBLE PERSONAL PENSION PLAN</fieldValue></objectFi
 eld><objectField> <fieldID>1015</fieldID><fieldName>tableId</fieldName><field
 Value>105A</fieldValue></objectField><objectField> <fieldID>1521</fieldID><fi
 eldName>policyId</fieldName><fieldValue>P00029867B02</fieldValue></objectFiel
 d><objectField> <fieldID>1522</fieldID><fieldName>policyNumber</fieldName><fi
 eldValue>P00029867B02</fieldValue></objectField><objectField> <fieldID>1534</
 fieldID><fieldName>planRef</fieldName><fieldValue>P00029867B</fieldValue></ob
 jectField><objectField> <fieldID>1112</fieldID><fieldName>earlyRetirementDate
 </fieldName><fieldValue>2010-11-19</fieldValue></objectField><objectField> <f
 ieldID>1523</fieldID><fieldName>retirementDate</fieldName><fieldValue>2010-11
 -19</fieldValue></objectField><objectField> <fieldID>1524</fieldID><fieldName
 >retirementAge</fieldName><fieldValue>0</fieldValue></objectField><objectFiel
 d> <fieldID>1525</fieldID><fieldName>pensionAmount</fieldName><fieldValue>100
 000.00</fieldValue></objectField><objectField> <fieldID>1118</fieldID><fieldN
 ame>jointAnnuityPerc</fieldName><fieldValue>0.00</fieldValue></objectField><o
 bjectField> <fieldID>1526</fieldID><fieldName>guaranteePeriod</fieldName><fie
 ldValue>5</fieldValue></objectField><objectField> <fieldID>1527</fieldID><fie
 ldName>escalationRate</fieldName><fieldValue>11.00</fieldValue></objectField>
 <objectField> <fieldID>1530</fieldID><fieldName>pensionType</fieldName><field
 Value>P</fieldValue></objectField><level5Object> <objectType>interests</objec
 tType><objectID>123</objectID><objectSeq>1</objectSeq><objectField> <fieldID>
 1528</fieldID><fieldName>partyInterestType</fieldName><fieldValue>BEN</fieldV
 alue></objectField><objectField> <fieldID>1529</fieldID><fieldName>partyId</f
 ieldName><fieldValue>7510135</fieldValue></objectField></level5Object><level5
 Object> <objectType>interests</objectType><objectID>123</objectID><objectSeq>
 2</objectSeq><objectField> <fieldID>1528</fieldID><fieldName>partyInterestTyp
 e</fieldName><fieldValue>LIN</fieldValue></objectField><objectField> <fieldID
 >1529</fieldID><fieldName>partyId</fieldName><fieldValue>7510134</fieldValue>
 </objectField></level5Object><level5Object> <objectType>interests</objectType
 ><objectID>123</objectID><objectSeq>3</objectSeq><objectField> <fieldID>1528<
 /fieldID><fieldName>partyInterestType</fieldName><fieldValue>PRO</fieldValue>
 </objectField><objectField> <fieldID>1529</fieldID><fieldName>partyId</fieldN
 ame><fieldValue>7510134</fieldValue></objectField></level5Object></level4Obje
 ct></level3Object></level2Object><level2Object> <objectType>party</objectType
So potentially, i need to cut everything after 'sending xml' to a new document.I had to delete some of the text as there was too much. When i have done that i will think about re arranging the xml in a hierarchical structure.

Thanks

Last edited by hugh86; 10-25-2010 at 01:32 PM.
 
Old 10-25-2010, 09:55 AM   #8
hugh86
LQ Newbie
 
Registered: Oct 2010
Posts: 9

Original Poster
Rep: Reputation: 0
HI guys, just wondering if the input/output file helped? I am still seeking help if anyone can.

Many Thanks,

Hugh
 
Old 10-26-2010, 11:01 AM   #9
hugh86
LQ Newbie
 
Registered: Oct 2010
Posts: 9

Original Poster
Rep: Reputation: 0
i still seek help wit this issue.
 
Old 10-26-2010, 01:22 PM   #10
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
awk '/Sending XML/,/Message Sending ended/' file | xmllint --format > file.xml


Cheers,
Tink
 
Old 10-26-2010, 09:48 PM   #11
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,564

Rep: Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901
Slight adjustment to tink's line as it will also print the included lines:
Code:
awk 'f;/Sending XML/,/Message Sending ended/{f=!f}' file | xmllint --format > file.xml
 
Old 10-27-2010, 03:56 AM   #12
hugh86
LQ Newbie
 
Registered: Oct 2010
Posts: 9

Original Poster
Rep: Reputation: 0
Hello,

Firstly thankyou for getting back to me - i was beginning to lose hope.

that code works but now i have a new problem.

Code:
 Sending XML          :

 <document> <docRequestID>2010-10-22-11.57.22.903813</docRequestID><docStylesh

 eet>Thunderhead</docStylesheet><requestType>claim</requestType><level0Object>

  <objectType>transaction</objectType><objectID>900</objectID><objectSeq>1</ob
 Line break has effected tag
 jectSeq><level1Object> <objectType>lifelite</objectType><objectID>901</object
As you can see, the line break has effected this tag half is on the line below and this XML cannot be used like that. I would like for it to remove the linespaces at the start of the line, looking like : </object>

thanks again

Hugh
 
Old 10-27-2010, 04:09 AM   #13
hugh86
LQ Newbie
 
Registered: Oct 2010
Posts: 9

Original Poster
Rep: Reputation: 0
Hello again,

Code:
sed -n '/Sending XML/,/Message sending ended/p' ${infile} > ${outfile}
this worked for me, i had to tweak what you sent me but i am still getting line spaces which is breaking up the xml.

Code:
#!/bin/bash
echo "Get my XML"
echo -n "Enter the source file name : "
read infile
echo -n "Enter output file name : "
read outfile
sed -n '/Sending XML/,/Message sending ended/p' ${infile} > ${outfile} 
echo "Data should be in $outfile if this compiled correctly"
Above is my code.
Cheers

Last edited by hugh86; 10-27-2010 at 04:15 AM. Reason: addition
 
Old 10-27-2010, 05:36 AM   #14
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,564

Rep: Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901
Well the xmllint didn't work for me and your sed has the same issue as the original awk that it prints the lines in your range.
Apart from that I get the chunk returned that you provided. I am guessing xmllint doesn't like the chunk I have as it is a fragment and
not complete.

Also neither sed nor awk are producing the extra spacing you are showing in post #12. If the file was generated on Windows I would be guessing the last character
of each line contains characters that unix does not like.
 
Old 10-27-2010, 07:05 AM   #15
hugh86
LQ Newbie
 
Registered: Oct 2010
Posts: 9

Original Poster
Rep: Reputation: 0
Hello,

Are you not getting the line spaces in the extracted xml then? I get one on every line.. any ideas how i can stop this?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Get data from multi lined text file using awk, sed or perl - grep & cut not upto par cam34 Programming 4 07-02-2010 04:10 AM
How to use grep, cut, or awk to get an IP from a file chudster Linux - General 4 02-03-2010 08:06 PM
How to use command grep,cut,awk to cut a data from a file? hocheetiong Linux - Newbie 7 09-11-2008 08:16 PM
sed/awk/grep for multiple line data hotrodmacman Programming 8 10-18-2007 12:06 PM
How do I cut out a specific piece of a html page (using sed/awk or similar)? bomix Linux - General 2 10-08-2005 05:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration