转载自http://kernel-of-linux.blogbus.com/logs/15569454.html

首先先编写这样一个SHELL程序,目的:把当前目录下的所有文件中的“EXT2”都改为“MYEXT2”。

在/home/xs的目录下建立substitute.sh

#mkdir xs

#cd xs

#touch substitute.sh

# vi substitute.sh

OK,现在已经进入到/home/xs(自己建立的用户目录)/substitute.sh文件中。

输入源码

#!/bin/sh

SCRIPT=substitute.sh

for f in * ;

do

    if [ $f = $SCRIPT ] ; then

        echo "skip $f"

        continue

    fi

echo -n "substitute ext2 to myext2 in $f..."

cat $f | sed 's/ext2/myext2/g'>${f}_tmp

mv ${f}_tmp $f

echo "done"

echo -n "substitute EXT2 to MYEXT2 in $f..."

cat $f | sed 's/EXT2/MYEXT2/g'>${f}_tmp

mv ${f}_tmp $f

echo "done"

done

源码完毕!保存退出。

最后,看看程序的效果,例如建立一个文件hello.c,现在可以把hello.c中所有的ext2和EXT2改为myext和

MYEXT2

相关文章:

  • 2021-08-29
  • 2022-12-23
  • 2021-11-20
  • 2021-07-12
  • 2022-12-23
  • 2021-07-16
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-04-01
  • 2021-06-08
  • 2021-08-12
  • 2021-08-01
  • 2021-12-15
  • 2021-12-31
相关资源
相似解决方案