Skip to content

Instantly share code, notes, and snippets.

@gonaumov
Created July 9, 2016 10:03
Show Gist options
  • Save gonaumov/f5c54753c530cc21e7cef9e5500ed74c to your computer and use it in GitHub Desktop.
Save gonaumov/f5c54753c530cc21e7cef9e5500ed74c to your computer and use it in GitHub Desktop.
#!/bin/bash
# A little practice with sed from Georgi Naumov
stringToAppend="# we want to add this string\n"
filePath="apache2.conf"
# This will add bellow commend before the first occurence
# of LogFormat
# -r extended regular expression
# -i - in place
sed -ri '0,/(\bLogFormat\b)/s//'"$stringToAppend"'\1/' $filePath
printf "All done!\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment