Skip to main content

Thread: Math function with sed or awk


i have file has sequence of repeating data looks this:


code:
height=42  align=left><a  href="download.php/myfile.zip><img    align="right"><b><a  align=center>  align=center><nobr>2011-09-25<br  align=center>175.17<br>mb</td>  align=center>469<br>times</td>  align=center><b><a  align=center>0</td>  align=left><a
how print previous 5 lines of file if line containing mb has value less 200?

thanks!

this not asked think might useful doing. me not easy use sed match new lines, i'd alter output have newlines i'd need them
code:
$ cat filename | tr '\n' '~' | sed 's/href\="/\nhref\=/g' | sed 's/mb<\/td>/mb<\/td>\n/g' | grep "mb<\/td>" | tr '~' ' '
from here you'd output like
code:
href=download2.php/myfile.zip><img  align="right"><b><a align=center> align=center><nobr>1911-09-25<br align=center>175.17<br>mb</td> href=download3.php/myfile.zip><img  align="right"><b><a align=center> align=center><nobr>2010-09-25<br align=center>999.22<br>mb</td> href=download4.php/myfile.zip><img  align="right"><b><a align=center> align=center><nobr>2011-09-25<br align=center>67.32<br>mb</td>
where important data on 1 line, making easier filter

edit:
dropping loop bc comparison, can see if it's less 200 mb
code:
$ in $(cat filename | tr '\n' '~' | sed 's/href\="/\nhref\=/g' | sed 's/mb<\/td>/mb<\/td>\n/g' | grep "mb<\/td>"); megabyte="$(echo $i | tr '~' ' ' | grep -o ">\([^<]*\)<br>mb" | cut -d\> -f2 | cut -d\< -f 1)"; if [ "$(echo "$megabyte < 200" | bc)" = "1" ]; echo $i | tr '~' ' '; fi; done
this yields
code:
href=download2.php/myfile.zip><img  align="right"><b><a align=center> align=center><nobr>1911-09-25<br align=center>175.17<br>mb</td> href=download4.php/myfile.zip><img  align="right"><b><a align=center> align=center><nobr>2011-09-25<br align=center>67.32<br>mb</td>


Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk [SOLVED] Math function with sed or awk


Ubuntu

Comments

Popular posts from this blog

how to devide a circle into equal parts

"Could not fill because there are not enough opaque source pixels" - not solved by any other thread

Why can't I change the billing info for my account?