首页 > 系统服务 > 详细

Bash Shell read file line by line and substring

时间:2015-04-13 08:13:09      阅读:228      评论:0      收藏:0      [点我收藏+]
#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 abcdefg
echo $input | cut -d= -f 2
echo $input | cut -d= -f 2


#${variable:startindex:len}
export str="123456789"
output=${str:3:3}
echo $output

#${varible##*string} 从左向右截取最后一个string后的字符串
#${varible#*string}  从左向右截取第一个string后的字符串
#${varible%%string*} 从右向左截取最后一个string后的字符串
#${varible%string*}  从右向左截取第一个string后的字符串

#常用保留变量:
$HOME:当前用户的根目录路径
$PATH:PATH环境变量
$PWD:当前工作路径
$0,$1,$2,…:第0个参数(shell脚本自身),第1个参数……
$RANDOM:1-65536之间的整数

Bash Shell read file line by line and substring

原文:http://www.cnblogs.com/huaxiaoyao/p/4421239.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!