Sed
From Attie's Wiki
(Difference between revisions)
(Created page with "==Follow a search for a file== <source lang="bash"> LD_LIBRARY_PATH=/opt/gst/lib/ GST_PLUGIN_PATH=/opt/gst/lib/gstreamer-0.10/ /opt/strace /opt/gst/bin/gst-inspect 2>&1 | tee ...") |
m |
||
(2 intermediate revisions by one user not shown) | |||
Line 1: | Line 1: | ||
+ | ==Usage== | ||
+ | <source lang="bash"> | ||
+ | # swap out text (just use regex) | ||
+ | sed -i 's/hello/goodbye/' ${FILE} | ||
+ | |||
+ | # delete line 5 | ||
+ | sed -i '5d' ${FILE} | ||
+ | |||
+ | # delete 2 lines, from line 5 | ||
+ | sed -i '5,+2d' ${FILE} | ||
+ | |||
+ | # delete the matching line | ||
+ | sed -i '/test string/d' ${FILE} | ||
+ | </source> | ||
+ | |||
==Follow a search for a file== | ==Follow a search for a file== | ||
+ | For example, while debugging a non-working GStreamer install: | ||
<source lang="bash"> | <source lang="bash"> | ||
− | LD_LIBRARY_PATH=/opt/gst/lib/ GST_PLUGIN_PATH=/opt/gst/lib/gstreamer-0.10/ /opt/strace /opt/gst/bin/gst-inspect 2>&1 | tee gst-inspect.out | grep -r ^open | sed -re 's#^(open\(")(([^"/]*/)*)([^"]*)(".* = )([-0-9]*)(.*)$#\4\t\6\t \1\2\4\5\6\7#' | sort | + | LD_LIBRARY_PATH=/opt/gst/lib/ GST_PLUGIN_PATH=/opt/gst/lib/gstreamer-0.10/ /opt/strace /opt/gst/bin/gst-inspect 2>&1 | |
+ | tee gst-inspect.out | | ||
+ | grep -r ^open | | ||
+ | sed -re 's#^(open\(")(([^"/]*/)*)([^"]*)(".* = )([-0-9]*)(.*)$#\4\t\6\t\1\2\4\5\6\7#' | | ||
+ | sort | ||
</source> | </source> |
Latest revision as of 01:02, 17 September 2012
[edit] Usage
# swap out text (just use regex) sed -i 's/hello/goodbye/' ${FILE} # delete line 5 sed -i '5d' ${FILE} # delete 2 lines, from line 5 sed -i '5,+2d' ${FILE} # delete the matching line sed -i '/test string/d' ${FILE}
[edit] Follow a search for a file
For example, while debugging a non-working GStreamer install:
LD_LIBRARY_PATH=/opt/gst/lib/ GST_PLUGIN_PATH=/opt/gst/lib/gstreamer-0.10/ /opt/strace /opt/gst/bin/gst-inspect 2>&1 | tee gst-inspect.out | grep -r ^open | sed -re 's#^(open\(")(([^"/]*/)*)([^"]*)(".* = )([-0-9]*)(.*)$#\4\t\6\t\1\2\4\5\6\7#' | sort