LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1287|回复: 8

awk中如何替换被正规式匹配的字符串?

[复制链接]
发表于 2006-6-9 12:15:50 | 显示全部楼层 |阅读模式
假设有如下url:
      http://www.myweb.com/files/file101.txt/
如何将其变为
    http://www.myweb.com/files/file102.txt/
发表于 2006-6-9 13:57:14 | 显示全部楼层
  1. awk 'sub(/01/,"02")'
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-6-9 17:59:29 | 显示全部楼层
因为我想根据一个url来动态生成一组连续的url,例如:
     http://www.myweb.com/files/file101.txt/
===》
     http://www.myweb.com/files/file102.txt/
       http://www.myweb.com/files/file103.txt/
                      ... ... ...
       http://www.myweb.com/files/file160.txt/
所以我想取出http://www.myweb.com/files/file1 ... ,不要见笑。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-6-9 18:00:18 | 显示全部楼层
因为我想根据一个url来动态生成一组连续的url,例如:
     http://www.myweb.com/files/file101.txt/
===》
     http://www.myweb.com/files/file102.txt/
       http://www.myweb.com/files/file103.txt/
                      ... ... ...
       http://www.myweb.com/files/file160.txt/
所以我想取出http://www.myweb.com/files/file1 ... ,不要见笑。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-6-9 18:01:51 | 显示全部楼层
因为我想根据一个url来动态生成一组连续的url,例如:
     http://www.myweb.com/files/file101.txt/
===》
     http://www.myweb.com/files/file102.txt/
       http://www.myweb.com/files/file103.txt/
                      ... ... ...
       http://www.myweb.com/files/file160.txt/
所以我想取出http://www.myweb.com/files/file1 ... ,不要见笑。
回复 支持 反对

使用道具 举报

发表于 2006-6-9 20:16:04 | 显示全部楼层
  1. #!/bin/sh
  2. URL=http://www.myweb.com/files/file
  3. ID=101
  4. for i in {101..160}
  5. do
  6.         echo "$URL$ID.txt/" >> file
  7.         let "ID+=1"
  8. done
复制代码
回复 支持 反对

使用道具 举报

发表于 2006-6-9 20:17:02 | 显示全部楼层

  1. #!/bin/sh

  2. URL=http://www.myweb.com/files/file
  3. ID=101

  4. for i in {101..160}
  5. do
  6.         echo "$URL$ID.txt/" >> file
  7.         let "ID+=1"
  8. done
复制代码
回复 支持 反对

使用道具 举报

发表于 2006-6-9 20:28:29 | 显示全部楼层
#!/bin/sh

URL=http://www.myweb.com/files/file
ID=101

while((ID<=160))
do
        echo "$URL$ID.txt/" >> file
        let "ID+=1"
done
回复 支持 反对

使用道具 举报

发表于 2006-6-9 20:31:44 | 显示全部楼层
#!/bin/sh

URL=http://www.myweb.com/files/file
ID=101

for i in $(seq 60)
do
        echo "$URL$ID.txt/" >> file
        let "ID+=1"
done
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表