sed -i 's:$: -y:' YOURFILE
Will do it for you.
-i
does the modification "in place", so no new file created (actully there's a tmp file)s
substitute:
delimiter$
end of line- see the 3. point
-y
replacement
문제
I have a file which looks like that:
sudo apt-get install rar
sudo apt-get install gimp
sudo apt-get install gnome-tweak-tool
sudo apt-get install unity-tweak-tool
sudo apt-get install pidgin
I want to somehow add "-y" in the end of each line, how is it done? Thanks
해결책
sed -i 's:$: -y:' YOURFILE
Will do it for you.
-i
does the modification "in place", so no new file created (actully there's a tmp file)s
substitute:
delimiter$
end of line-y
replacement다른 팁
Assuming you want to add -y
(change it as you deem appropriate) at the end of each line, you can use sed
by saying
$ cat file
sudo apt-get install rar
sudo apt-get install gimp
sudo apt-get install gnome-tweak-tool
sudo apt-get install unity-tweak-tool
sudo apt-get install pidgin
$ sed 's/$/ -y/' file
sudo apt-get install rar -y
sudo apt-get install gimp -y
sudo apt-get install gnome-tweak-tool -y
sudo apt-get install unity-tweak-tool -y
sudo apt-get install pidgin -y
This prints on standard out. If you wish to make in-place changes inside the file, you can use -i
option of sed
by saying
sed -i 's/$/ -y/' file
or redirect the output to another file by doing
sed 's/$/ -y/' file > newfile
If you are vi
mode you can try
:%s/$/text_to_be_added/g and press "Enter"
If you are bash
mode you can try
sed 's/$/text_to_be_added/g' filename