Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

change file content bash

sed -i 's/search_string/replace_string/' filename
Comment

edit text file bash

sudo nano file.text
Comment

bash modify file text

sed -i -e 's/abc/XYZ/g' /tmp/file.txt
Comment

auto modify text in files bash

sed -i -e 's/search_string/replace_string/g' filename

# And with variables:

search_string="example"
replace_string="replacement"
file_name="filename.txt"
sed -i "s/$search_string/$replace_string/" $file_name

‘-i’ # option is used to modify the content of the original file
# with the replacement string if the search string exists in the file.

‘s’ # indicates the substitute command.

‘search_string’ # contains the string value that will be searched in the
# file for replacement.

‘replace_string’ # contains the string value that will be used to replace
# the content of the file that matches the  ‘search_string’ value.

‘filename’ # contains the filename where the search and replace willbe applied.

# The ‘awk’ command is another way to replace the string in a file,
# but this command cannot update the original file directly like the ‘sed’ command.
Comment

PREVIOUS NEXT
Code Example
Shell :: current directory terminal mac 
Shell :: truncate log file linux 
Shell :: delete folder in linux 
Shell :: github api tutorial 
Shell :: batch open url 
Shell :: bash tokenize string 
Shell :: wget mac robot 
Shell :: git squash commit 
Shell :: redis cache start 
Shell :: How do i search for available packages from the command-line 
Shell :: git diff between branches file 
Shell :: push subtree to github pages 
Shell :: install admin lte in laravel 
Shell :: install flutter in android studio 
Shell :: global yarn install 
Shell :: ft2build.h: No such file or directory fedora 
Shell :: scp bash command 
Shell :: npm install 
Shell :: remove write proteced in usb ubuntu 
Shell :: aws lightsail ssl installation 
Shell :: npm i postgresql 
Shell :: github desktop 
Shell :: add folders to gitignore 
Shell :: ffmpeg extract single frame 
Shell :: ubuntu default tmux shell 
Shell :: delete a git branch 
Shell :: terminal show running processes tree mac os 
Shell :: raspberry pi remote desktop 
Shell :: Err:9 http://ppa.launchpad.net/plushuang-tw/uget-stable/ubuntu focal Release 404 Not Found [IP: 91.189.95.85 80] 
Shell :: docker run --entrypoint bash 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =