linux - Shell script translate single into multiple lines based on a parameter -
i try write shell scrip following data
input file page.txt content:
enter first page title<br><div style="margin-left: 40px;">enter first point <br></div><div style="margin-left: 80px;">enter second point<br></div><div style="margin-left: 120px;">enter third point<br></div><div style="margin-left: 80px;"><br></div><div style="margin-left: 40px;"><br></div><div style="margin-left: 40px;"><br></div>
algorithm :
read pages file replace <br> newline replace <div style="margin-left: 40px;"> 1 tab replace <div style="margin-left: 80px;"> 2 tab replace <div style="margin-left: 120px;"> 3 tab replace <div style="margin-left: 160px;"> 4 tab
i trying use
tr '<br>' '\n' < page.txt
expected output file
enter first page title enter first point enter second point enter third point
please tell tell how write script mentioned above..
i don't handle xml tags without parser, in specific case data seems weird (bad formed) perl , option evaluate replacement string in substitution command tool solution.
i use 3 substitution commands, first 1 replace <br>
newlines, second 1 remove close div
tags, , third 1 open div
tags, extract number of attribute , use calculate how many tabs insert:
perl -pe ' s/<br>/\n/g; s{</div>}{}g; s{\q<div style="margin-left: \e(\d+)\s*\qpx;">}{"\t" x ($1/40)}ge ' infile
it yields:
enter first page title enter first point enter second point enter third point
Comments
Post a Comment