Thread: Math function with sed or awk
i have file has sequence of repeating data looks this:
how print previous 5 lines of file if line containing mb has value less 200?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
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
from here you'd output likecode:$ cat filename | tr '\n' '~' | sed 's/href\="/\nhref\=/g' | sed 's/mb<\/td>/mb<\/td>\n/g' | grep "mb<\/td>" | tr '~' ' '
where important data on 1 line, making easier filtercode: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>
edit:
dropping loop bc comparison, can see if it's less 200 mb
this yieldscode:$ 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
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
Post a Comment