Skip to content

Instantly share code, notes, and snippets.

@lutter
Created June 7, 2018 22:47
Show Gist options
  • Save lutter/b28328ecc532d052c950175c120164bc to your computer and use it in GitHub Desktop.
Save lutter/b28328ecc532d052c950175c120164bc to your computer and use it in GitHub Desktop.
#! /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