User avatar
Void Frost
Posts: 48
Joined: Sun Jul 01, 2018 2:13 am

Sed command not working

Sun Apr 07, 2019 5:57 pm

Hello! I'm trying to make an easier way to overclock a Pi, and i'm trying to echo the new arm_freq=1500 to the config.txt on line 78 but for some reason it won't copy over. My command is as follows:

Code: Select all

sudo sed -i 78i\arm_freq=1500 /boot/config.txt
Raspberry Pi User. Subscribe to my YouTube channel, if you want :D https://www.youtube.com/c/VoidFrost

tpyo kingg
Posts: 549
Joined: Mon Apr 09, 2018 5:26 pm
Location: N. Finland

Re: Sed command not working

Sun Apr 07, 2019 6:17 pm

There are not normally 78 lines in config.txt, at least not by default. So the condition will never be met and the insertion never made. If you would like to append to the file, try something like this to insert or append on the final line:

Code: Select all

sudo sed -i.bak '$i\arm_freq=1500' /boot/config.txt

# or

sudo sed -i.bak '$a\arm_freq=1500' /boot/config.txt
The $ stands for the end of the file.

jahboater
Posts: 4421
Joined: Wed Feb 04, 2015 6:38 pm

Re: Sed command not working

Sun Apr 07, 2019 6:29 pm

Or just:

echo "arm_freq=1500" >>/boot/config.txt

User avatar
rpdom
Posts: 14412
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Sed command not working

Sun Apr 07, 2019 7:59 pm

jahboater wrote:
Sun Apr 07, 2019 6:29 pm
Or just:

echo "arm_freq=1500" >>/boot/config.txt
Which will fail because of permissions. The sudo is required.

You'd need to use something like

Code: Select all

sudo sh -c "echo 'arm_freq=1500' >>/boot/config.txt"
Yes, I do block a very small number of people.

No, I'm not going to name them. That would be childish.

User avatar
Void Frost
Posts: 48
Joined: Sun Jul 01, 2018 2:13 am

Re: Sed command not working

Sun Apr 07, 2019 10:33 pm

Is there a way I can easily add lines?
Raspberry Pi User. Subscribe to my YouTube channel, if you want :D https://www.youtube.com/c/VoidFrost

echmain
Posts: 210
Joined: Fri Mar 04, 2016 8:26 pm

Re: Sed command not working

Mon Apr 08, 2019 12:25 am

Void Frost wrote:
Sun Apr 07, 2019 10:33 pm
Is there a way I can easily add lines?

Any reason you can't use an editor? Vi or Nano or whatever?

tpyo kingg
Posts: 549
Joined: Mon Apr 09, 2018 5:26 pm
Location: N. Finland

Re: Sed command not working

Mon Apr 08, 2019 4:56 am

Void Frost wrote:
Sun Apr 07, 2019 10:33 pm
Is there a way I can easily add lines?
Yes, you can append using either sed or as shell redirection. Both methods are shown above. An advantage of using sed with -i is that it can create a backup file. The advantage of the appending redirection >> is that it is simple.

Can you please say a little about your task? Depending on the context there might be something else important.

jahboater
Posts: 4421
Joined: Wed Feb 04, 2015 6:38 pm

Re: Sed command not working

Mon Apr 08, 2019 2:03 pm

tpyo kingg wrote:
Mon Apr 08, 2019 4:56 am
Void Frost wrote:
Sun Apr 07, 2019 10:33 pm
Is there a way I can easily add lines?
Yes, you can append using either sed or as shell redirection. Both methods are shown above. An advantage of using sed with -i is that it can create a backup file. The advantage of the appending redirection >> is that it is simple.
If adding multiple lines from the shell, its common to use something called a "here document":-

Code: Select all

cat <<end >>/boot/config.txt
line 1
line 2
line 3
end
As noted above, you need root to write to /boot

Return to “General programming discussion”