sed 's/要被替换的字符串/新的字符串/g' sed 's/test/mytest/g' example-----在整行范围内把test替换为mytest. 如果没有g标记,则只有每行第一个匹配的test被替换成mytest. ed -i 's/被替换的内容/要替换成的内容/' file -i 直接修改并保存
读取文件的每一行内容并输出 #!/bin/bash # 方法1 while read line do echo $line done < a.txt # 方法2 cat a.txt | while read line do echo $line done # 方法3 # for line in `cat a.txt` for line in $(cat a.txt) do echo $line done 文件内容排序工具 sort 和 uniq sort:sort是一个以行为单位对文件内容进行排
Linux下Python 文件替换脚本 import sys,os if len(sys.argv)<=4: old_text,new_text = sys.argv[1],sys.argv[2] file_name = sys.argv[3] f = open(file_name,"rb") new_file = open(".%s.bak" % file_name,"wb") for line in f.xreadlines(): pr
1. Sed的help 鸟哥说的 学东西 先看 help 先看man 再google 不好FQ再百度.. Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]... -n, --quiet, --silent suppress automatic printing of pattern space -e script, --expression=script add the script to the comma
shell编程系列13--文本处理三剑客之sed利用sed追加文件内容 追加用法总结: .a 在匹配行后面追加 .i 在匹配行前面追加 .r 将文件内容追加到匹配行后面 .w 将匹配行写入指定文件 追加用法示例详解: .a ().passwd文件第10行后面追加"Add Line Behind" sed -i '10aAdd Line Behind' passwd ().passwd文件第10行到第20行,每一行后面都追加"Test Line Behind" sed