Editing/Replacing content in multiple files in Unix AIX without opening it

后端 未结 2 1801
渐次进展
渐次进展 2020-12-04 01:19

I have multiple files in Unix directory. files names are as below.
EnvName.Fullbkp.schema_121212_1212_Part1.expd EnvName.Fullbkp.schema_121212_1212_Part2.expd

相关标签:
2条回答
  • 2020-12-04 01:42

    It's some kind of extreme optimist who suggests sed -i on AIX.

    It's a bit more likely that perl will be installed.

    perl -pi -e 's/10022012_0630/22052013_1000/' EnvName.Fullbkp.schema_121212_1212_Part*.expd
    

    If no perl, then you'll just have to do it like a Real Man:

    for i in EnvName.Fullbkp.schema_121212_1212_Part*.expd
    do
      ed -s "$i" <<'__EOF'
    1,$s/10022012_0630/22052013_1000/g
    wq
    __EOF
    done
    

    Have some backups ready before trying these.

    0 讨论(0)
  • 2020-12-04 01:59

    Assuming you mean you don't want to manually open the files:

    sed -i 's/10022012_0630/22052013_1000/' filename*.log
    

    update: since the "-i" switch is not available on AIX, but assuming you have ksh (or a compatible shell):

    mkdir modified
    for file in filename*.log; do
        sed 's/10022012_0630/22052013_1000/' "$file" > modified/"$file"
    done
    

    Now the modified files will be in the modified directory.

    0 讨论(0)
提交回复
热议问题