EMBED YOUR TERMINAL RECORDINGS ONLINE

Poor man's text patcher

DATE: 2012-02-21
AUTHOR: Coder of Salvation
AUTHOR WWW: http://leon.vankammen.eu
RELATED ARTICLE: http://leon.vankammen.eu/shellscript-framework

Related recordings:

M4, THE HIDDEN GNU TREASURE
tags: m4, gnu, macroprocessor, template, search, replace, sed
THE UNIX TREE COMMAND
tags: unix console tree bash directory listing
CD -
tags: bash
NOTITLE
tags: bash variable search replace
CONDITIONAL CRON USING DATE %A
tags: cron shellscript conditional bash schedule
CUT TEXT FROM CONSOLE OUTPUT
tags: cut manipulate text bash shellscript
FORMATTING OUTPUT WITH COLUMN
tags: formatting output shellscript column cut
AIRCRACK-NG - MODE MONITOR
tags: aircrack-ng monitor mode bash
VIM MAPPINGMANAGER PLUGIN
tags: vim editor text vi bash keyboard shortcut mapping
BASH EVENT DESIGNATOR
tags: bash history events designator trick shortcut





EMBED THIS RECORDING:
<div><script id="playterm-MjAxMi0wMi9wYXRjaGh0bWx0dHlyZWMtMTMyOTg1NjAwOHw4MHgyNA==" type="text/javascript" src="https://playterm.org/js/?hash=MjAxMi0wMi9wYXRjaGh0bWx0dHlyZWMtMTMyOTg1NjAwOHw4MHgyNA==" class="size:80x24"></script></div>
I recorded this `poor man's text patcher` shellsession because I was trying to find a way easily
edit/read patchfiles for generated html.
This is a simplified example of the patchsystem I wrote. Commands used:

sed -i "s/searchterm/replacement/g" somefile.html
m4 patch.m4

varname=$(cat foo.html)

ps. don't forget to use ` and ' for m4 strings (not '' or "")

Mike said

Wut!??
's/REPLACE/target'
You do not need to escape target that much. Just escape the backslashes - sed accepts POSIX2
regexes, and in POSIX2 regexes the characters have a special meaning only when preceded by a
backslash.

coderofsalvation said

agreed, thanks!

coderofsalvation said

btw. I also noticed sed also excepts '|' as delimiter.
This is really handing when inserting urls without escaping like:
's|%url%|http://playterm.org/flop/flap'

 

Name   
Email (never shown)  
Comment