0

I copy /etc/default/keybord and make a keyboard2 file.

When I cat the file I get :

# KEYBOARD CONFIGURATION FILE

# Consult the keyboard(5) manual page.

XKBMODEL="pc105"
XKBLAYOUT="fr"
XKBVARIANT=""
XKBOPTIONS=""

BACKSPACE="guess"

Then I sed s/fr/us/ keyboard2 and immediatlly displays :

# KEYBOARD CONFIGURATION FILE

# Consult the keyboard(5) manual page.

XKBMODEL="pc105"
XKBLAYOUT="us"
XKBVARIANT=""
XKBOPTIONS=""

BACKSPACE="guess"

But when I cat keyboard2 again, I got :

# KEYBOARD CONFIGURATION FILE

# Consult the keyboard(5) manual page.

XKBMODEL="pc105"
XKBLAYOUT="fr"
XKBVARIANT=""
XKBOPTIONS=""

BACKSPACE="guess"
                  

tested with sudo, tested puting the 's/fr/us/'

Did I understood something wrong ? Is sed supposed to write into the file or do I need to pipe and overwrite the original file ? Thank you

Versions:

sed (GNU sed) 4.7
Linux kali 5.9.0-kali5-amd64 #1 SMP Debian 5.9.15-1kali1 (2020-12-18) x86_64 GNU/Linux in Oracle Virtual Box
1
  • Found that the i flag needs to be in the command to overwrite the file. solved Commented Jan 24, 2021 at 14:09

2 Answers 2

1

You are right in that you understood something wrong. Sed is indeed not supposed to overwrite the input file so, as you guessed, you will have to redirect (pipe) the output to a different file, e.g.:

sed 's/fr/us/' /etc/default/keyboard > keyboard2

then move keyboard2 to /etc/default/keyboard (don't forget to make a backup copy of the original file, just in case).

Sign up to request clarification or add additional context in comments.

Comments

0

What @sebbit wrote should work, but sed dose have option to write to the change the file directly.
Just add -i flag this will change the file you reading from
Like this:

sed -i s/fr/us/ keyboard2

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.