Linux Bash shell one practice : array if else
shell practice 1
1.require
A B C D
1 2 3 4
5 6 7 8
3 5 8 0
1 2 4 3
after handling:
T A B C D
A 1 2 3 4
B 5 6 7 8
C 3 5 8 0
D 1 2 4 3
1.first need read the first line as an array.
then append the element in the proper position for file;
oldifs=$IFS
IFS=$'\n';
counter=0;
cols=''
for line in $(cat test.txt);
do
if [ $counter -eq 0 ]; then
IFS=$' '
read -a cols <<< "$line";
echo 'T ' $line > test_new.txt;
IFS=$'\n';
else
echo "${cols[counter-1]} " $line>>test_new.txt;
fi
let counter++;
done;
cat test_new.txt;
IFS=$oldifs;
Linux Bash shell one practice : array if else的更多相关文章
- linux BASH shell设置字体与背景颜色
linux BASH shell下设置字体及背景颜色的方法. BASH shell下设置字体及背景颜色 echo -e "\e[31mtest\e[41m" \e[30m 将字 ...
- 【Linux】linux bash shell之变量替换::=句法、=句法、:-句法、-句法、=?句法、?句法、:+句法、+句法
linux bash shell之变量替换::=句法.=句法.:-句法.-句法.=?句法.?句法.:+句法.+句法 linux bash shell之变量替换::=句法.=句法.:-句法.-句法. ...
- Linux Bash Shell常用快捷键
Linux Bash Shell常用快捷键 table { margin: auto } 快捷键 功能 tab 补全 ctrl + a 光标回到命令行首 ctrl + e 光标回到命令行尾 ctrl ...
- Linux bash shell All In One
Linux bash shell All In One Linux https://tinylab.gitbooks.io/shellbook/content/zh/chapters/01-chapt ...
- linux bash shell & lsof & grep & ps
linux bash shell & lsof & grep & ps lsof list all open files # lsof & grep $ lsof -P ...
- Linux Bash Shell 快速入门
BASH 的基本语法 最简单的例子 —— Hello World! 关于输入.输出和错误输出 BASH 中对变量的规定(与 C 语言的异同) BASH 中的基本流程控制语法 函数的使用 2.1 ...
- linux bash shell 流程控制(if/else )
本文转自:http://blog.csdn.net/flowingflying/article/details/5069646 本文也即<Learning the bash Shell>3 ...
- (转)linux bash shell 入门教程
Shell Script(bash)简介 众所皆知地,UNIX上以小工具著名,利用许多简单的小工具,来完成原本需要大量软体开发的工作,这一点特色,使得UNIX成为许多人心目中理想的系统平台. 在众多的 ...
- Linux Bash Shell入门教程
Linux 系统根据 "#!" 及该字串后面的信息确定该文件的类型,关于这一问题同学们回去以后可以通过 "man magic"命令 及 /usr/share/m ...
随机推荐
- extjs grid renderer用法
extjs grid renderer用法 摘自:http://www.cnblogs.com/ljian/archive/2011/10/27/2226959.html var cm = new E ...
- bootstrap 学习片段
1. 只要单击按钮添加了data-toggle="dropdown"属性, 在单击按钮的时候,默认隐藏的下拉列表就会显示出来 <div class="row&quo ...
- ahjesus 获取当前方法被调用执行的具体位置,包括命名空间和方法
MethodBase method = ).GetMethod(); string ahjesus = method.ReflectedType.FullName + "." + ...
- 设计模式之Builder (创建者模式)的一些个人理解(转)
对于Builder模式很简单,但是一直想不明白为什么要这么设计,为什么要向builder要Product而不是向知道建造过程的Director要.刚才google到一篇文章,总算清楚了.在这里转贴一下 ...
- nodeJS中npm常见的命令
常用的nodeJS中npm的命令:npm主要是node包管理和发布的工具.npm常用的命令:1:npm install <name> //(下载包) 下载后的包放在当前路径下面 npm i ...
- js中this的理解
平常用this很多,对this的理解就是this是对应执行环境,然而很多时候效果并不是想要的,最近看了一些谈到this的笔记和书籍,总结下. 对this的误解: this是指向函数本身 先上个demo ...
- RHEL7文件权限
本文介绍Linux下的文件权限 操作系统为RHEL7.2_X86_64 可以从以下三种访问方式限制访问权限: 1 只允许用户自己访问 2 允许一个预先指定的用户组中的用户访问 3 允许系统中的任何用户 ...
- andriod 图片选择器
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="ht ...
- andriod 获取电池的信息
<?xml version="1.0"?> <LinearLayout android:orientation="vertical" andr ...
- andriod 读取网络图片
来自:http://blog.csdn.net/jianghuiquan/article/details/8641283 Android手机上,我们常用ImageView显示图片,我们本章获取网络图片 ...