SED 替换索引字段

SED replace indexed field

是否可以替换定界字符串中按其位置寻址的字段?

aaa;bbb;ccc;ddd;sdfsfsdfsf;2324234234;dfdffdf;

用某些东西替换字段 5。


Here is my solution:

To replace a field NN+1 with BLAH in a semicolon delimited string:

    sed 's/\(\([^;]\+;\)\{NN\}\)[^;]\+;\(.*\)/BLAH;/'

for the PCRE variant:

    sed -r s/(([^;]*;){NN})[^;]*;(.*)/BLAH;/g

Thanks!

没有 sed.. 但是..

awk 'BEGIN{FS=OFS=";"} {="something"; print [=10=]}' input.txt

这可能适合您 (GNU sed):

sed 's/[^;]*/something/5' file

这是我的解决方案:

要用分号分隔的字符串中的 BLAH 替换字段 NN+1:

sed 's/\(\([^;]\+;\)\{NN\}\)[^;]\+;\(.*\)/BLAH;/'

对于 PCRE 变体:

sed -r s/(([^;]*;){NN})[^;]*;(.*)/BLAH;/g

谢谢!