AIX:sed 命令删除除第一行以外的所有行的模式
AIX : sed command to delete pattern for all the lines except the first
使用 AIX 7.X,我的 gnuplot 脚本有这些行:
set terminal png truecolor size 1950, 650 background rgb "#eff1f0"
set output "/xxx/xxxx/xxx/xxx/xxx.png"
set datafile separator ';'
set size ratio 0.2
set bmargin at screen 0.2
unset key
set datafile separator ";"
set ylabel " MB BLOCK " font ",10" offset -1,0
set xlabel font ",10"
set xtics rotate by 45 offset -0.8,-9,-1.8
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5
我想删除所有行的模式“plot”,除了第一行...用我的linux我这样做:
sed '0,/plot/! s/plot//g' myfile.txt
结果是:
set terminal png truecolor size 1950, 650 background rgb "#eff1f0"
set output "/var/IBMtools/www/tim/used.png"
set datafile separator ';'
set size ratio 0.2
set bmargin at screen 0.2
unset key
set datafile separator ";"
set ylabel " MB BLOCK " font ",10" offset -1,0
set xlabel font ",10"
set xtics rotate by 45 offset -0.8,-9,-1.8
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
"xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
"xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
"xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
"xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
"xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
"xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
"xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
"xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
"xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
"xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
"xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
"xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5
但是这个命令不适用于 AIX。错误是 sed: 0602-403 0,/plot/! s/plot//g is not a recognized function.
拜托,你能告诉我怎么做吗?
如果您可以接受 awk
解决方案,请尝试以下操作。
awk '/plot/ && ++count==1{print;next} !/plot/' Input_file
说明:为以上代码添加说明。
awk ' ##Starting awk program from here.
/plot/ && ++count==1{ ##Checking condition if string plot is present and variable count value is 1 then do following.
print ##Printing the current line.
next ##next will skip all further statements from here.
} ##Closing BLOCK for above condition.
!/plot/ ##Checking condition if string plot is NOT present then do print of that line.
' Input_file ##Mentioning Input_file name here.
注意: 如果您想将输出保存到 Input_file 本身,然后将 > temp && mv temp Input_file
附加到上面代码。
如果 plot 不在文件的第一行,你可以这样做:
sed '1,/plot/!s/plot//'
如果能在第一行,我看没办法只能循环:
sed ':a;/plot/!{n;ba;};:b;n;s///;bb'
使用 AIX 7.X,我的 gnuplot 脚本有这些行:
set terminal png truecolor size 1950, 650 background rgb "#eff1f0"
set output "/xxx/xxxx/xxx/xxx/xxx.png"
set datafile separator ';'
set size ratio 0.2
set bmargin at screen 0.2
unset key
set datafile separator ";"
set ylabel " MB BLOCK " font ",10" offset -1,0
set xlabel font ",10"
set xtics rotate by 45 offset -0.8,-9,-1.8
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5
我想删除所有行的模式“plot”,除了第一行...用我的linux我这样做:
sed '0,/plot/! s/plot//g' myfile.txt
结果是:
set terminal png truecolor size 1950, 650 background rgb "#eff1f0"
set output "/var/IBMtools/www/tim/used.png"
set datafile separator ';'
set size ratio 0.2
set bmargin at screen 0.2
unset key
set datafile separator ";"
set ylabel " MB BLOCK " font ",10" offset -1,0
set xlabel font ",10"
set xtics rotate by 45 offset -0.8,-9,-1.8
plot "xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
"xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
"xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
"xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
"xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
"xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
"xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
"xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
"xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
"xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
"xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
"xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
"xx/xx/file.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5
但是这个命令不适用于 AIX。错误是 sed: 0602-403 0,/plot/! s/plot//g is not a recognized function.
拜托,你能告诉我怎么做吗?
如果您可以接受 awk
解决方案,请尝试以下操作。
awk '/plot/ && ++count==1{print;next} !/plot/' Input_file
说明:为以上代码添加说明。
awk ' ##Starting awk program from here.
/plot/ && ++count==1{ ##Checking condition if string plot is present and variable count value is 1 then do following.
print ##Printing the current line.
next ##next will skip all further statements from here.
} ##Closing BLOCK for above condition.
!/plot/ ##Checking condition if string plot is NOT present then do print of that line.
' Input_file ##Mentioning Input_file name here.
注意: 如果您想将输出保存到 Input_file 本身,然后将 > temp && mv temp Input_file
附加到上面代码。
如果 plot 不在文件的第一行,你可以这样做:
sed '1,/plot/!s/plot//'
如果能在第一行,我看没办法只能循环:
sed ':a;/plot/!{n;ba;};:b;n;s///;bb'