2

Grep several patterns from a file and save them in different files

 2 years ago
source link: https://www.codesd.com/item/grep-several-patterns-from-a-file-and-save-them-in-different-files.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Grep several patterns from a file and save them in different files

advertisements

Hi I have an mpd which has the following information

<BaseURL>01/</BaseURL>
                                <SegmentList timescale="1000">
                                        <SegmentTimeline>
                                                <S t="0" d="11477" dtv:lastVideoPTS="1126034"/>
                                                <S t="11477" d="11111" dtv:lastVideoPTS="2126033"/>
                                                <S t="22588" d="11200" dtv:lastVideoPTS="3132038"/>
                                                <S t="33789" d="11422" dtv:lastVideoPTS="4162067"/>
                                                <S t="45211" d="11711" dtv:lastVideoPTS="5219123"/>
                                                <S t="56923" d="11177" dtv:lastVideoPTS="6222125"/>
                                                <S t="68101" d="11478" dtv:lastVideoPTS="7252154"/>
 </SegmentTimeline>
                                        <SegmentURL media="1.ts" mediaRange="0-3424419"/>
                                        <SegmentURL media="2.ts" mediaRange="0-8063319"/>
                                        <SegmentURL media="3.ts" mediaRange="0-7146631"/>
                                        <SegmentURL media="4.ts" mediaRange="0-8984143"/>
                                        <SegmentURL media="5.ts" mediaRange="0-7496499"/>
                                        <SegmentURL media="6.ts" mediaRange="0-10445091"/>
                                        <SegmentURL media="7.ts" mediaRange="0-8854423"/>
</SegmentList>
                        </Representation>
                        <Representation id="02" bandwidth="2066992" width="896" height="720" scanType="progressive">
                                <BaseURL>02/</BaseURL>
                                <SegmentList timescale="1000">
                                        <SegmentTimeline>
                                                <S t="0" d="11477" dtv:lastVideoPTS="1126034"/>
                                                <S t="11477" d="11244" dtv:lastVideoPTS="2135042"/>
                                                <S t="22722" d="11878" dtv:lastVideoPTS="3207113"/>
                                                <S t="34600" d="11778" dtv:lastVideoPTS="4270175"/>
                                                <S t="46379" d="11945" dtv:lastVideoPTS="5345249"/>
                                                <S t="58324" d="11945" dtv:lastVideoPTS="6417320"/>
                                                <S t="70270" d="11911" dtv:lastVideoPTS="7489391"/>
                                                <S t="82181" d="11478" dtv:lastVideoPTS="8522423"/>
 </SegmentTimeline>
                                        <SegmentURL media="1.ts" mediaRange="0-1801039"/>
                                        <SegmentURL media="2.ts" mediaRange="0-3065151"/>
                                        <SegmentURL media="3.ts" mediaRange="0-2842747"/>
                                        <SegmentURL media="4.ts" mediaRange="0-3216303"/>
                                        <SegmentURL media="5.ts" mediaRange="0-2798943"/>
                                        <SegmentURL media="6.ts" mediaRange="0-3977891"/>
                                        <SegmentURL media="7.ts" mediaRange="0-3301843"/>

I want to grep for base url/01 what are all the segment urls and for base url/02 what are all the segment urls can you please help as I am new to scripting...

The desired output I am looking for is for base url/01 saved into a different file and the same for base url/02

<BaseURL>01/</BaseURL>
<SegmentURL media="1.ts" mediaRange="0-3424419"/>
                                        <SegmentURL media="2.ts" mediaRange="0-8063319"/>
                                        <SegmentURL media="3.ts" mediaRange="0-7146631"/>
                                        <SegmentURL media="4.ts" mediaRange="0-8984143"/>
                                        <SegmentURL media="5.ts" mediaRange="0-7496499"/>
                                        <SegmentURL media="6.ts" mediaRange="0-10445091"/>
                                        <SegmentURL media="7.ts" mediaRange="0-8854423"/>


I suggest you the use of xml2 (http://www.ofb.net/~egnor/xml2/) to transform the xml to something grep-able.

Unfortunately the xml you posted seems broken to me, please update the question.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK