Shell遍历文件的每一行
由于使用for来读入文件里的行时,会自动把空格和换行符作为一样分隔符,因为当行里有空格的时候,输出的结果会很乱,所以……
cat input.txt |while read line
> do
> echo $line
> done
或者:
while read line
> do
> echo $line
> done < input.txt
再举个实际点的例子(把所有目录权限修改为755,所有文件为644):
# find ./ -type f>filelist
# find ./ -type d>dirlist
# cat dirlist |while read i; do chmod 755 "${i}"; done
# cat filelist |while read i; do chmod 644 "${i}"; done
转载自:http://www.hao32.com/unix-linux/338.html
Shell遍历文件的每一行的更多相关文章
- Shell遍历文件的每一行[转载]
#!/bin/sh while read line do echo $line done < /home/jms/lab/input.txt
- shell读取文件的每一行内容并输出【转】
写法一: #!/bin/bash while read line do echo $line done < file(待读取的文件) 写法二: #!/bin/bash cat file(待读取的 ...
- Shell遍历文件,对每行进行正则匹配
Shell查看文件的最后5行,并对每行进行正则匹配,代码如下: #!/bin/sh pattern="HeartBeat" /home/test/log/log_20150205. ...
- shell遍历文件夹
遍历目录下的所有文件 假如有一个文件夹路径为dir,遍历文件 for file in /path/dir/* do if test -f $file then echo $file arrary=($ ...
- shell遍历文件夹并执行命令
背景: 有一个源码包里面包含很多子目录和makefile,打包后的压缩包太大,需要将make生成的所有二进制文件删除然后再打包. 需求: 因此,要求在制定目录的所有递归子目录中执行make clean ...
- shell读取文件的每一行
写法一: ---------------------------------------------------------------------------- #!/bin/bash while ...
- (转)shell:读取文件的每一行内容并输出
写法一:----------------------------------------------------------------------------#!/bin/bashwhile rea ...
- shell遍历文件
取文件每行的数据,需要按列取 可以 sed 加管道 使用 awk 取列 platform="list.txt" line=`grep -vc '^$' $platform` ; ...
- shell 读取文件的每一行内容并输出
(1)#!/bin/bash while read linedo echo $linedone < file (2)#!/bin/bash cat file | while read l ...
随机推荐
- 初学 Canvas <第一篇-基础篇>
本文摘自:兴趣部落大神(为你一生画眉)-讲一讲canvas究竟是个啥? HTML5 的标准已经出来好久了,但是似乎其中的 Canvas 现在并没有在太多的地方用到.一个很重要的原因是,Canvas 的 ...
- 每天一条Linux命令(OS X系统上操作)
Linux菜鸟必学的60个命令 安装和登录命令:login.shutdown.halt.reboot.install.mount.umount.chsh.exit.last: 文件处理命令:file ...
- windows服务安装(System.ComponentModel.Win32Exception:远程过程调用失败)
“安装”阶段发生异常.System.ComponentModel.Win32Exception:远程过程调用失败 附上提示信息C:\Windows\Microsoft.NET\Framework\v4 ...
- linux list all users.
cat /etc/passwd sample of list users in linux. ref: Linux Command: List All Users In The System
- sql server identity限制
identity属性是依赖于表的,它不是一种独立的序列机制,不能随意使用它生成新值. 标识值是在insert语句执行时生成的,不是在执行之前生成的. identity属性是以异步的方式分配标识值.这意 ...
- Swift - 31 - 常量参数, 变量参数和inout参数
//: Playground - noun: a place where people can play import UIKit // swift中默认情况下, 传入的参数是不可以修改的, 也就是l ...
- ASP.NET Core中使用Razor视图引擎渲染视图为字符串
一.前言 在有些项目需求上或许需要根据模板生产静态页面,那么你一样可以用Razor语法去直接解析你的页面从而把解析的页面生成静态页,这样的使用场景很多,不限于生成静态页面,视图引擎为我们提供了模型到视 ...
- mktime性能问题
#include <time.h> int main() { for (int i = 0; i < 100000; ++i) { struct tm tm = {}; tm.tm_ ...
- C# Trim方法去除字符串两端的指定字符
var str= ",2,3,4,6,7,"; var str2 = str.Trim(new char[] { ',' }); //去除字符串str两端的','字符. //则st ...
- C# ,asp.net 获取当前,相对,绝对路径(转)
C# ,asp.net 获取当前,相对,绝对路径 一.C#获取当前路径的方法: . System.Diagnostics.Process.GetCurrentProcess().MainModule. ...