【问题标题】:AIX : sed command to delete pattern for all the lines except the firstAIX:sed 命令删除除第一行之外的所有行的模式
【发布时间】:2020-04-14 21:02:12
【问题描述】:

在 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.

拜托,你能告诉我怎么做吗?

【问题讨论】:

  • 你可以试试seq 3 | sed -n '1,2p'吗? seq 3 | sed -n '1,/2/p'? seq 3 | sed '1,/2/s/1/a/'?哦,我认为0 作为地址不是posix,sed '1,/plot/!s/plot//' 可以工作吗?
  • 您好,我添加了一些细节以便更清楚!
  • @HK2432,请问我的解决方案是否对您有所帮助?

标签: sed gnuplot aix


【解决方案1】:

如果您对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 附加到上述代码中。

【讨论】:

    【解决方案2】:

    如果绘图不在文件的第一行,你可以这样做:

    sed '1,/plot/!s/plot//'
    

    如果它可以在第一行,我认为除了循环之外别无他法:

    sed ':a;/plot/!{n;ba;};:b;n;s///;bb'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-27
      • 1970-01-01
      • 1970-01-01
      • 2011-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多