LinuxSir.cn,穿越时空的Linuxsir!

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

[求助]文件内容分割问题...

[复制链接]
发表于 2005-5-8 18:14:22 | 显示全部楼层 |阅读模式
自己4了几种办法不成功... 希望有空的能帮忙看看. 谢谢.
这是文件一部分内容...
  1. <text id="fld-sharing">Folder sharing</text>
  2. <text id="fld-sharing-add-user">Add user</text>
  3. <text id="fld-sharing-add-group">Add group</text>
  4. <text id="fld-sharing-add-all">Add all users</text>
  5. <text id="fld-sharing-all-users">All authenticated users</text>
  6. <text id="fld-sharing-user">User</text>
  7. <text id="fld-sharing-level">Permission level</text>
  8. <text id="fld-sharing-owner">Owner</text>
  9. <text id="fld-sharing-administrator">Administrator</text>
  10. <text id="fld-sharing-editor">Editor</text>
  11. <text id="fld-sharing-reader">Reader</text>
  12. <text id="fld-sharing-none">None</text>
复制代码

提取出来的效果如下...

  1. Folder sharing
  2. Add user
  3. Add group
  4. Add all users
  5. All authenticated users
  6. User
  7. Permission level
  8. Owner
  9. Administrator
  10. Editor
  11. Reader
  12. None
复制代码


然后把这些单词翻译成中文....
如下.

  1. 共享此文件夹
  2. 添加用户
  3. 添加组
  4. 添加所有用户
  5. 验证所有用户
  6. 用户
  7. 共享级别
  8. 所有者
  9. 管理员
  10. 编辑
  11. 读取
  12. 关闭共享
复制代码

插入到文件内去效果如下.
  1. <text id="fld-sharing">共享此文件夹</text>
  2. <text id="fld-sharing-add-user">添加用户</text>
  3. <text id="fld-sharing-add-group">添加组</text>
  4. <text id="fld-sharing-add-all">添加所有用户</text>
  5. <text id="fld-sharing-all-users">验证所有用户</text>
  6. <text id="fld-sharing-user">用户</text>
  7. <text id="fld-sharing-level">共享级别</text>
  8. <text id="fld-sharing-owner">共享所有者</text>
  9. <text id="fld-sharing-administrator">管理员</text>
  10. <text id="fld-sharing-editor">编辑</text>
  11. <text id="fld-sharing-reader">读取</text>
  12. <text id="fld-sharing-none">关闭共享</text>
复制代码

请问用shell怎么分割.. 谢谢...
发表于 2005-5-8 19:39:27 | 显示全部楼层
翻译这一步不会也要用shell做吧?
回复 支持 反对

使用道具 举报

发表于 2005-5-8 22:00:50 | 显示全部楼层
提取应该可以
  1. sed "s/<[^>]*>//g" file
复制代码

翻译的话shell好象不行吧
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-5-8 22:46:59 | 显示全部楼层
翻译那步 不需要shell做.。 后面那个插入怎么办?
回复 支持 反对

使用道具 举报

发表于 2005-5-9 07:59:54 | 显示全部楼层
插入的话比较麻烦,看来是否只能一行一行的插入?
回复 支持 反对

使用道具 举报

发表于 2005-5-9 09:57:56 | 显示全部楼层
我想用paste后,再用sed替换一下。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-5-9 10:47:56 | 显示全部楼层
cu那边有人帮忙解决了... 贴出来大家共勉一下..
  1. /home/lee#cat a
  2. <text id="fld-sharing">Folder sharing</text>
  3. <text id="fld-sharing-add-user">Add user</text>
  4. <text id="fld-sharing-add-group">Add group</text>
  5. <text id="fld-sharing-add-all">Add all users</text>
  6. <text id="fld-sharing-all-users">All authenticated users</text>
  7. <text id="fld-sharing-user">User</text>
  8. <text id="fld-sharing-level">Permission level</text>
  9. <text id="fld-sharing-owner">Owner</text>
  10. <text id="fld-sharing-administrator">Administrator</text>
  11. <text id="fld-sharing-editor">Editor</text>
  12. <text id="fld-sharing-reader">Reader</text>
  13. <text id="fld-sharing-none">None</text>
  14. /home/lee#cat b
  15. 共享此文件夹
  16. 添加用户
  17. 添加组
  18. 添加所有用户
  19. 验证所有用户
  20. 用户
  21. 共享级别
  22. 所有者
  23. 管理员
  24. 编辑
  25. 读取
  26. 关闭共享
复制代码
  1. /home/lee#\
  2. > while read -u3 a && read -u4 b;do
  3. > echo $a|sed "s/>.*</>$b</" >>c.txt
  4. > done 3<a 4<b
  5. /home/lee#cat c.txt
  6. <text id="fld-sharing">共享此文件夹</text>
  7. <text id="fld-sharing-add-user">添加用户</text>
  8. <text id="fld-sharing-add-group">添加组</text>
  9. <text id="fld-sharing-add-all">添加所有用户</text>
  10. <text id="fld-sharing-all-users">验证所有用户</text>
  11. <text id="fld-sharing-user">用户</text>
  12. <text id="fld-sharing-level">共享级别</text>
  13. <text id="fld-sharing-owner">所有者</text>
  14. <text id="fld-sharing-administrator">管理员</text>
  15. <text id="fld-sharing-editor">编辑</text>
  16. <text id="fld-sharing-reader">读取</text>
  17. <text id="fld-sharing-none">关闭共享</text>

复制代码

谢谢大家帮忙.
回复 支持 反对

使用道具 举报

发表于 2005-5-9 14:56:23 | 显示全部楼层
Post by zhy2111314
提取应该可以
  1. sed "s/<[^>]*>//g" file
复制代码

翻译的话shell好象不行吧


能解释一下为什么么?
回复 支持 反对

使用道具 举报

发表于 2005-5-9 15:27:12 | 显示全部楼层
  1. sed "s/<[^>]*>//g" file
复制代码

s/oldstring/newstring/g
这个是sed中全局替换的基本用法
然后
<[^>]*>的意思是匹配
从<开始到紧跟着<的下一个>结束,如果使用<.*>的话就会最大匹配,也就是从第一个<开始直到这一行的最后一个>结束,也就不满足要求了
回复 支持 反对

使用道具 举报

发表于 2005-5-9 18:16:26 | 显示全部楼层
Post by zhy2111314
  1. sed "s/<[^>]*>//g" file
复制代码

s/oldstring/newstring/g
这个是sed中全局替换的基本用法
然后
<[^>]*>的意思是匹配
从<开始到紧跟着<的下一个>结束,如果使用<.*>的话就会最大匹配,也就是从第一个<开始直到这一行的最后一个>结束,也就不满足要求了


还不是很明白 ..

sed "s/<[^>]*>//g" file

这个我的理解是 :
"s/<[^>]*>//g"
配置以<开头 到 第一个> 为结束中间的字符串  ..  因为用了^
<text id="fld-sharing">Folder sharing</text>
也就是 <text id="fld-sharing"> 这段  , 后面的 又怎么解释呢  ~  </text> 这个又是怎么删除的!
回复 支持 反对

使用道具 举报

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

本版积分规则

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