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 ...
随机推荐
- 与众不同 windows phone (50) - 8.1 新增控件: PickerFlyout, ListPickerFlyout
[源码下载] 与众不同 windows phone (50) - 8.1 新增控件: PickerFlyout, ListPickerFlyout 作者:webabcd 介绍与众不同 windows ...
- HTML5 Audio and JavaScript Control
IE8 以下无效 <!DOCTYPE html> <html> <head> <meta content="text/html; charset=u ...
- IOC容器中bean的生命周期
一.Bean的生命周期 Spring IOC容器可以管理Bean的生命周期,允许在Bean生命周期的特定点执行定制的任务. Spring IOC容器对Bean的生命周期进行管理的过程如下: (1).通 ...
- Spring RMI Example
一: 提供服务的远程一端 1-1. applicationContext.xml <?xml version="1.0" encoding="UTF-8" ...
- Scala Collection简介
Traversable vs Iterable Traversable, Iterable 都是trait. Iterable 继承 Traversable. Traversable: 支持forea ...
- 如何给span设置高度宽度?
内容提要:给Span设置高度和宽度后没有作用.本文介绍了如何如何给span设置高度宽度. CSS模型中经常用的容器是DIV和span. 给Span设置高度和宽度后没有作用. <style typ ...
- Sass学习之路(1)——Sass简介
Sass是CSS的一种预处理器语言,类似的语言还有Less,Stylus等. 那么什么是CSS预处理器? CSS 预处理器定义了一种新的语言,其基本思想是,用一种专门的编程语言,为 CSS 增加了一些 ...
- Javascript对象赋值操作
首先,我们还是举个例子来说明对象赋值操作的问题吧: ps: 本文默认约定log = console.log function A(){} A.prototype.x = 10; var a1 = ne ...
- CSS3中的calc()
什么是calc()? calc是英文单词calculate(计算)的缩写,是css3的一个新增的功能; MDN的解释为可以用在任何长度,数值,时间,角度,频率等处; /* property: calc ...
- SharePoint 2013 的HTML5特性之响应式布局
今天偶然看到一本书<Pro SharePoint 2013 Branding and Responsive Web Development>,看到SharePoint 2013基于HTML ...