print lines 3 through 7 of a file: sed -n '3,7p' somefile | sed -i '4s/xxx/bbb/' f1

print lines 3 through 7 of a file: sed -n '3,7p' somefile

Trim leading and trailing whitespace
sed -i 's/^[ \t]*//;s/[ \t]*$//' somefile
============


sed -i 'Ns/.*/replacement-line/' file.txt
where N should be replaced by your target line number. This replaces the line in the original file. To save the changed text in a different file, drop the -i option:

sed 'Ns/.*/replacement-line/' file.txt > new_file.txt
centos@192 Documents]$ sed -i '2s/aaa/bbb/' f1
[centos@192 Documents]$ cat f1
aaa
bbb
aaa
bbb
aaa

Comments

Popular posts from this blog

HAproxy logging

teamcity Automatic Agent Start under Linux

NFS mount add in fstab _netdev instead of default | firewall-cmd --list-all