Bug with the 'Linux String Substitute (sed)' task (write access to the folder missing?)

The task seems to have an issue with access rights. So it states that:

There is some data on Nautilus App Server 3 in Stratos DC . Data needs to be altered in several of the files. On Nautilus App Server 3 , alter the /home/BSD.txt file as per details given below:
a. Delete all lines containing word software and save results in /home/BSD_DELETE.txt file. (Please be aware of case sensitivity)
b. Replace all occurrence of word from to their and save results in /home/BSD_REPLACE.txt file.
Note: Let’s say you are asked to replace word to with from . In that case, make sure not to alter any words containing this string; for example up to , contribu to r etc.

This is what I have there:

$ ls -al
total 28
drwxr-xr-x 1 root root 4096 Jul 31 01:04 .
drwxr-xr-x 1 root root 4096 Jul 31 01:04 …
drwx------ 1 ansible ansible 4096 Oct 15 2019 ansible
drwx------ 1 banner banner 4096 Jan 25 2020 banner
-rw-r–r-- 1 root root 9919 Jul 31 01:04 BSD.txt

So when I try to create a file it just fails to do it due to access rights:

[banner@stapp03 home]$ touch BSD_REPLACE.txt
touch: cannot touch ‘BSD_REPLACE.txt’: Permission denied
[banner@stapp03 home]$ sed ‘s/ from / their /g/’ BSD.txt > BSD_REPLACE.txt
-bash: BSD_REPLACE.txt: Permission denied

It doesn’t let me to create files in the ‘home’ directory, while the task requires the - ‘/home/BSD_DELETE.txt’ doesn’t exist on …’

Hi @frsempervivam ,
Please make use of the sudo command.

sudo sed 's/ from / their /g/' BSD.txt > BSD_REPLACE.txt

Above command will work.
When you get the password prompt, type the password of the sudo user.

Hi there, I am using sudo to change delete lines that contains software word and I keep getting permission denied, could you please help?

Thank you

@Giacomo1

This command has two parts.

  1.  sed '/software........'
    
  2. > BSD_DELETE.txt
    

sudo only worked for the first part and that’s why you got permission error. If you want sudo to work for both part.
Try this

sudo bash -c “sed '/software… > BSD_DELETE.txt”