Bash Shell read file line by line and substring
#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
Bash Shell read file line by line and substring的更多相关文章
- 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 ...
- 解决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 ...
- Shell脚本:while read line无法读取最后一行的问题
[1]Shell脚本:while read line无法读取最后一行的问题 刚刚利用shell脚本处理日志文件时,发现了一个问题:while read line无法读取到最后一行 通过编辑器可以看到待 ...
- 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 * ...
- 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 ...
- 安装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 ...
- (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 ...
- 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 ...
- 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 ...
随机推荐
- Android开发总是难以入门
发现自己很难入门,是真的太难,还是自己主观拒绝.
- DP入门---饭卡
HDU 2546 Description 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额 ...
- AC自动机---病毒侵袭
HDU 2896 题目网址: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=110773#problem/B Description 当太 ...
- 【图解】Eclipse下JRebel6.2.0热部署插件安装、破解及配置【转】
标签: 这两天在做后台管理系统,前端框架用Bootstrap,后端用SpringMVC+Velocity.在开发过程中,经常需要对界面进行微调,调整传参等,每次更改一次java代码,就得重新部署一次, ...
- Web网站数据”实时”更新设计
请注意这个实时打上了双引号,没有绝对的实时,只是时间的颗粒不一样罢了(1ms,1s,1m). 服务器数据有更新可以快速通知客户端.Web 基于取得模式,而服务器建立大量的和客户端连接来提供数据实时更新 ...
- The main concepts
The MVC application model A Play application follows the MVC architectural pattern applied to the we ...
- js中this的理解
平常用this很多,对this的理解就是this是对应执行环境,然而很多时候效果并不是想要的,最近看了一些谈到this的笔记和书籍,总结下. 对this的误解: this是指向函数本身 先上个demo ...
- 配置SharePoint使用ADFS
1. 如果网站应用程序没有使用声明式验证 $wpp = Get-SPWebApplication <URL> $wpp.UseClaimsAuthentication = 1 $wpp.U ...
- Fragments之间的交互(实现参数传递)
Fragments之间的交互(实现参数传递) 日常开发中,通常Fragments之间可能需要交互,比如基于用户事件改变Fragment的内容.所有Fragment之间的交互需要通过他们关联的Activ ...
- 【转载】iOS堆和栈的理解
操作系统iOS 中应用程序使用的计算机内存不是统一分配空间,运行代码使用的空间在三个不同的内存区域,分成三个段:“text segment “,“stack segment ”,“heap segme ...