Results 1 to 3 of 3
is there a way to replace text strings in a file from the command line (no scripts or programming)?
I want to replace this line in /etc/inittab
Code:
id:5:initdefault:
with
...
- 08-06-2007 #1
command for replacing text?
is there a way to replace text strings in a file from the command line (no scripts or programming)?
I want to replace this line in /etc/inittab
withCode:id:5:initdefault:
(replace 5 with 3)Code:id:3:initdefault:
im making a test and trying to make setup into a single multipart command. what would the command line be?
thx
- 08-06-2007 #2
The sed utility can do pattern matching and replacement. So for your particular example:
This would print the modified file to the terminal. You could redirect that into a temp file and replace the original with it. Or you could use the '-i' option to backup the existing copy and automatically make the change. Check the man page for more details.Code:sed -e 's/id:5:initdefault/id:3:initdefault/' /etc/inittab
sed uses a technique called regular expressions to match patterns in the file. You can do very powerful things with it: find an online resource on regular expressions for more info.DISTRO=Arch
Registered Linux User #388732
- 08-06-2007 #3


Reply With Quote
