User Tools

Site Tools


Manipulate File based on list

File_line = list
Edit_file = httpd.conf
for i in $File_line; do
sed "s#DocumentRoot $i#DocumentRoot $i \\
php_admin_value open_basedir \"$i:/tmp\"#" $Edit_file
#sed -i.bak "s#DocumentRoot $i#DocumentRoot $i \\
#php_admin_value disable_functions \"exec,system,passthru,readfile,shell_exec,escapeshellarg,escapeshellcmd,proc_close,proc_open,ini_alter,dl,popen,parse_ini_file,show_source\"#" httpd.conf

sed to insert line after string match

  • -i will allow you to write to file and create backup
  • -e will allow for bash expression such as '\t' to be completed (tab insertion)
  • usage: '/pattern to find/a the text you want to add'
sed -i.bak  -e '/type slave/a \\t masters {; } ;' named.conf
sed_based_file_manipulation.txt · Last modified: 2020/08/10 02:35 (external edit)