(1)使用awk将文件的前12列替换为空
awk '{for(i=1;i<=12;i++)$i="";print $0}' localhost_access_log //写法一 awk '{for(i=1;i<=12;i++){$i=""};print $0}' localhost_access_log //写法二 awk '{for(i=13;i<=NF;i++)printf $i" ";printf "\n"}' localhost_access_log //写法三
(2)去除开头的空格
sed 's/^ *//' 5201351.txt //这样只能匹配空格开头 sed 's/^\s*//' 5201351.txt //也可以这样写,除了空格还可以匹配制表符 sed 's/^[[:space:]]*//' 5201351.txt //也可以这样写,除了空格还可以匹配制表符 sed 's/ \+//g' 5201351.txt //