1 按行读取数据

shell中for循环的默认分隔符是:空格、tab、\n

需求是只以\n作为分隔符
shell for循环以\n作为分割符,方式一:

文件aa.sh
#!/bin/bash


IFS=$'\n'

for i in `cat 1.txt`;
do
echo "begin"
echo $i
echo "end"
done

 

2 linux系统中删除文件的最后几行

2.1head

head -n -3 a.txt

2.2 sed

tac a.txt | sed '1,3d' | tac

3  AWK 

3.1 函数替换

awk '{print $'$1'}'

4 每两行文本合并为一行

cat a.txt|xargs -l2

xargs -l2 < a.txt

5 grep 

5.1 grep 多条件

grep -E 'a|b' 满足 a 或 b 都行

5.2 grep 同时满足

grep a|grep b 同时满足a\b

6 tr命令详解

6.1 字符由大写转换为小写

echo "HELLO WORLD" | tr 'A-Z' 'a-z'

6.2 将制表符转换为空格

cat text | tr '\t' ' '

7 column排版

7.1 排版

在查看文本时,是否对于对不齐的信息看起来很难受,总是找错呢?
这时候就想 到 Excel 时多么的友好啊~~
不过不用担心,今天就带你领略下在linux 命令窗口下进行上下左右对齐的快感。

-t:格式化显示
-s:指定分隔符,默认就按照空格

column -t -s$'\t' tmp.txt |less -SN

 

整理自:

https://blog.csdn.net/Sweblish/article/details/8725426

Linux 上下对齐,格式化显示---column_毒鸡蛋的博客-CSDN博客

 posted on 2022-05-10 09:40  xibuhaohao  阅读(87)  评论(0)    收藏  举报