#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
echo $input | cut -d'=' -f #${variable:startindex:len}
export str=""
output=${str::}
echo $output #${varible##*string} 从左向右截取最后一个string后的字符串
#${varible#*string} 从左向右截取第一个string后的字符串
#${varible%%string*} 从右向左截取最后一个string后的字符串
#${varible%string*} 从右向左截取第一个string后的字符串 #常用保留变量:
$HOME:当前用户的根目录路径
$PATH:PATH环境变量
$PWD:当前工作路径
$,$,$,…:第0个参数(shell脚本自身),第1个参数……
$RANDOM:-65536之间的整数 #大小写转换
HI=HellO
 
echo "$HI" # HellO
echo ${HI^} # HellO
echo ${HI^^} # HELLO
echo ${HI,} # hellO
echo ${HI,,} # hello
echo ${HI~} # hellO
echo ${HI~~} #hELLo
^大写,,小写, ~大小写切换
重复一次只修改首字母,重复两次则应用于所有字母
#字符串的替换
${file/dir/path}:将第一个 dir 提换为 path:/path1/dir2/dir3/my.file.txt
${file//dir/path}:将全部 dir 提换为 path:/path1/path2/path3/my.file.txt
 
ref:http://my.oschina.net/leejun2005/blog/368777
 

Bash Shell read file line by line and substring的更多相关文章

  1. How to build .apk file from command line(转)

    How to build .apk file from command line Created on Wednesday, 29 June 2011 14:32 If you don’t want ...

  2. 解决Warning: unlink(/storage/cache/cache.catalog.language.1556158719): No such file or directory in /system/library/cache/file.php on line 68问题

    ytkah在调试opencart项目时提示Warning: unlink(/storage/cache/cache.catalog.language.1556158719): No such file ...

  3. Shell脚本:while read line无法读取最后一行的问题

    [1]Shell脚本:while read line无法读取最后一行的问题 刚刚利用shell脚本处理日志文件时,发现了一个问题:while read line无法读取到最后一行 通过编辑器可以看到待 ...

  4. SyntaxError: Non-UTF-8 code starting with '\xe5' in file ***.py on line 105, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for

    用charles抓包时, 对抓到的html,放到pycharm中解析, 结果报错: SyntaxError: Non-UTF-8 code starting with '\xe5' in file * ...

  5. Java 8 Stream – Read a file line by line

    In Java 8, you can use Files.lines to read file as Stream. c://lines.txt – A simple text file for te ...

  6. 安装Phoenix时./sqlline.py执行报错File "./sqlline.py", line 27, in <module> import argparse ImportError: No module named argparse解决办法(图文详解)

    不多说,直接上干货! 前期博客 Apache版Phoenix的安装(图文详解) 问题现象 Traceback (most recent call last): File , in <module ...

  7. (C++) Assertion failed: !"Bad error code", file VMem.c, line 715

    (C++) Assertion failed: !"Bad error code", file VMem.c, line 715 Misc error. myInterface F ...

  8. Traceback (most recent call last): File "setup.py", line 22, in <module> execfile(join(CURDIR, 'src', 'SSHLibrary', 'version.py')) NameError: name 'execfile' is not defined

    在python3环境下安装robotframework-SSHLibraray报错: Traceback (most recent call last): File "setup.py&qu ...

  9. mysql InnoDB: Assertion failure in thread xxxx in file ut0mem.cc line 105

    mysql InnoDB: Assertion failure in thread xxxx in file ut0mem.cc line 105 错误信息 InnoDB: Assertion fai ...

随机推荐

  1. Python入门笔记(22):Python函数(5):变量作用域与闭包

    一.全局变量与局部变量 一个模块中,最高级别的变量有全局作用域. 全局变量一个特征就是:除非被删除,否则他们存活到脚本运行结束,且对于所有的函数都可访问. 当搜索一个标识符(也称变量.名字等),Pyt ...

  2. 与众不同 windows phone (35) - 8.0 新的启动器: ShareMediaTask, SaveAppointmentTask, MapsTask, MapsDirectionsTask, MapDownloaderTask

    [源码下载] 与众不同 windows phone (35) - 8.0 新的启动器: ShareMediaTask, SaveAppointmentTask, MapsTask, MapsDirec ...

  3. LeetCode127:Word Ladder II

    题目: Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) ...

  4. spring注解配置启动过程

    最近看起spring源码,突然想知道没有web.xml的配置,spring是怎么通过一个继承于AbstractAnnotationConfigDispatcherServletInitializer的 ...

  5. Spring 接口代理 类代理

    1.Question Description : when you use @Transactional annotation and @RequiresPermissions annotation ...

  6. mybatis generator with oracle

    1.generator.xml <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE generat ...

  7. 记录php日志

    1.记录PHP错误日志 display_errors与log_errors的区别 display_errors 错误回显,一般常用于开发模式,但是很多应用在正式环境中也忘记了关闭此选项.错误回显可以暴 ...

  8. 求Mac 的adt插件!

    搞了半天原来ADT Mac和win是通用的安装方法也相同! 自己配环境! 下载一个Eclipse,然后安装就行! dns:203.195.223.190 这个DNS可以连上谷歌的服务器(只限学习使用) ...

  9. win10应用部署到手机出现问题Exception from HRESULT: 0x80073CFD

    今天把应用部署到手机上时,出现了这样的问题 Exception from HRESULT: 0x80073CFD 具体错误是: Error Error : DEP0001 : Unexpected E ...

  10. UDF2

    问题 根据给定的gps点point(x,y)和北京的shape数据,关联出 AOI ID IO 输入 gps点表 create table gps ( x double, //经度 y double ...