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
Shmuel
  • 1,568
  • 10
  • 20
av3rag3
  • 11

2 Answers2

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).

sebbit
  • 111
  • 3
  • 4
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
Shmuel
  • 1,568
  • 10
  • 20