[shell] while read line 与for循环的区别 while read line 与for循环的区别---转载整理 while read line 是一次性将文件信息读入并赋值给变量line ,while中使用重定向机制,文件中的所有信息都被读入并重定向给了整个while 语句中的line 变量. for是每次读取文件中一个以空格为分割符的字符串. 如下示例脚本: #/bin/bash IPS="10.1.1.10 3001 10.1.1.10 3003 10.1.1.11 3
#read one file line by line for line in $(cat test1.txt); do echo $line ; done; #while read split line by space while read line do for word in $line do echo $word done; done <test1.txt #string split or substring input=type=abcdefg echo $input; #get a
修改执行部分的代码,改成用InputStream.read(byte[])的方法从流中读取数据 package com.example.demo.utils; import java.io.*; public class CMDExecute { public synchronized String run(String cmd) throws IOException { String line = null; String result = ""; try { String[] co
If you want to delete lines 5 through 10 and 12: sed -e '5,10d;12d' file This will print the results to the screen. If you want to save the results to the same file: sed -i.bak -e '5,10d;12d' file This will back the file up to file.bak, and delete th