how do i change this text for a specific line
Suppose I want to change line 50, and I want to change 8 letters after "user": like the example below which I bold
line 50 "user": " 9077c266 -8944-11eb-a9d1-fa163e4be1a2"
Use the s
command in sed
to search and replace.
sed -i 'Ns/9077c266/replacement-line/' file.txt
where N
should be replaced by your target line number.
To save the changed text in a different file, drop the -i option:
sed 'Ns/9077c266/replacement-line/' file.txt > new_file.txt
I would used sed either by line number or just content if it's unique:
sed -i '50s/9077c266/replacement/' file.txt
or:
sed -i 's/9077c266/replacement/' file.txt
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.