I'm trying to replace the path part of below line from postgresql.conf using shell script:
data_directory = '/var/lib/postgresql/10/main' # use data in another directory
I first checked if I'm able to locate the line first using below script, but it did not find the line:
#!/bin/bash
while IFS='' read -r line || [[ -n "$line" ]]; do
if [[ "$line" = "data_directory = '/var/lib/postgresql/10/main' # use data in another directory" ]]
I know there is better way to replace this line using sed, but I need to know if its doable by reading the file from start to end and then replace the desired part of the line, if found. If not, replacing the entire line with only the path part changed will do it too. Thanks!
${var/find/replace}.sed" or "sedis okay but I do not know how." I have answered the latter.sedbut I want to do it using loop and all because I'm not familiar with it and I know loop will be useful for me in other scenarios as well. Learning!#in the string you're comparing with$linethan the line you gave as an example.