Skip to content

Instantly share code, notes, and snippets.

@lutter
Created Jun 7, 2018
Embed
What would you like to do?
#! /bin/bash
# Use as 'lines.sh /some/file'
# The file we want to manipulate
src=/tmp/lines.txt
# The line we are looking for (including quotes !)
line="'Include $1'"
# This is ugly but works with released augeas going a long way back
if augtool -e -At "Simplelines incl $src" "match /files/tmp/lines.txt/*[. = $line]" | grep -q '(no matches)'
then
augtool -e -At "Simplelines incl $src" <<EOF
ins 01 after /files$src
set /files$src/01 $line
save
EOF
fi
# This will work with augeas-1.11.0 (not released yet)
# We disable it with 'if false'
# See https://github.com/hercules-team/augeas/pull/563
if false
then
if ! augmatch -q -l Simplelines -m "*[$line]" $src
then
augtool -e -At "Simplelines incl $src" <<EOF
ins 01 after /files$src
set /files$src/01 $line
save
EOF
fi
fi
# Basic example file for Simplelines lens
line 1 value # comment line 1
line 2 value # comment line 2
Include /some/file
Include /some/other/file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment