Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
sed无法识别AIX上的-r标志_Sed_Aix - Fatal编程技术网

sed无法识别AIX上的-r标志

sed无法识别AIX上的-r标志,sed,aix,Sed,Aix,提前谢谢你的帮助 我有一行代码在linux上运行 myfile(摘录) 结果将是: 1;O7_DICTIONARY_ACCESSIBILITY=TRUE 2;active_instance_count= 3;aq_tm_processes=1 4;archive_lag_target=0 5;audit_file_dest=?/rdbms/audit 6;audit_sys_operations=FALSE 7;audit_trail=NONE 8;background_core_dump=pa

提前谢谢你的帮助

我有一行代码在linux上运行

myfile(摘录)

结果将是:

1;O7_DICTIONARY_ACCESSIBILITY=TRUE
2;active_instance_count=
3;aq_tm_processes=1
4;archive_lag_target=0
5;audit_file_dest=?/rdbms/audit
6;audit_sys_operations=FALSE
7;audit_trail=NONE
8;background_core_dump=partial
9;background_dump_dest=/home1/oracle/app/oracle/admin/iopecom/bdump
但是,我不知道如何在AIX服务器上执行相同的命令

非常欢迎帮助

问候


Antonio。

除非您有充分理由使用
sed
,否则您可以使用其他工具:

awk -v OFS=';' '{print NR,$0}' filename
将产生所需的输出

您还可以使用
perl

perl -ne 'print "$.;$_"' filename

您的
sed
表达式似乎会跳过以
#
开头的行。因此,你可以说:

perl -ne '$,=";"; !/^#/ && print ++$i,$_' filename
或者类似于:

grep -v '^#' filename | awk ...

重新格式化管道:

cat myfile |
        sed -r 's/ {1,}//g'   | # strip all spaces                     (1)
        sed -r 's/\t*//g'     | # strip all tabs                       (2)
        grep -v "^#"          | # delete all lines beginning `#`       (3)
        sed -s "/^$/d"        | # delete all empty lines               (4)
        sed =                 | # interleave with line numbers         (5)
        sed 'N;s/\n/\t/'      | # join line number and line with `\t`  (6)
        sed -r "s/#.*//g"     | # strip all `#` comments               (7)
        sed "s/\t/;/g"        | # replace all tabs with `;`            (8)
        sed "s/\t/;/g"        | # do it again                          (9)
        sed -e "s,',\o042,g"    # replace all ' with "                (10)
将其煮沸,然后使用
cat-n
预先提供行号:

cat -n myfile                  |
    sed "$(print 's/\t/;/')
         $(print 's/[ \t]*//g')
         s/#.*//g
         /^$/d
         s/'/\"/g"

除非我误读了aix文档,否则它的行为是相同的。
$(…)
构造是命令替换,它运行该命令并替换其输出
print
在linux上应该是
printf

你好,谢谢,是的,我用了你这样的回复
cat myfile | grep-v“^ |”| awk…
@user3665737没有必要
grep | awk
,当然也没有必要
cat | grep | awk
。您可以执行
awk-vofs=';''/^#/{print++i,$0}'我的文件
解释得很好,但是为什么
$()
cat-nyourfile | sed“s//;s//[]*///g;s//#.*///g;//^$/d;s/'/\“/g”
其中长空格为实选项卡char@NeronLeVelu因为它更容易阅读,演示了一种有用的技术,并且不难看到结果并将其细分,就像您所做的那样。
cat myfile |
        sed -r 's/ {1,}//g'   | # strip all spaces                     (1)
        sed -r 's/\t*//g'     | # strip all tabs                       (2)
        grep -v "^#"          | # delete all lines beginning `#`       (3)
        sed -s "/^$/d"        | # delete all empty lines               (4)
        sed =                 | # interleave with line numbers         (5)
        sed 'N;s/\n/\t/'      | # join line number and line with `\t`  (6)
        sed -r "s/#.*//g"     | # strip all `#` comments               (7)
        sed "s/\t/;/g"        | # replace all tabs with `;`            (8)
        sed "s/\t/;/g"        | # do it again                          (9)
        sed -e "s,',\o042,g"    # replace all ' with "                (10)
cat -n myfile                  |
    sed "$(print 's/\t/;/')
         $(print 's/[ \t]*//g')
         s/#.*//g
         /^$/d
         s/'/\"/g"