Notes of the shell (10)

1. Delete the last letter in the first line and delete the second-to-last character in the second line and delete the n-th letter in the second line. Is there any way to achieve this?

ABCDEFG
ABCDEFG
ABCDEFG
ABCDEFG
ABCDEFG

awk problem solving:

awk 'BEGIN{FS=OFS=""}{if(NF>=NR)$(NF-NR+1)="";print}' txt

Insert picture description here
analysis:
Insert picture description here

Second, how to take the content in the last parenthesis in regular. (Hello) I am Chinese (Yes)

#1
(?<=)[\u4e00-\u9fa5]{
    
    2}(?!.*[\u4e00-\u9fa5]{
    
    2})(?=)

#2
echo '(您好)我是中国人(是的)啊啊啊啊' | grep -Po '.*(\K[^)]+'

#3
sed -r 's#.*((.*?))$.*#\1#' zhongwen.txt

Insert picture description here
Insert picture description here

3. Now through the shell, print 00, 01, 02, 03, 04 on the first day, and print 05, 06, 07, 08, 09, ... on the tenth day, print 45, 46, 47, 48, 49, Then the eleventh day starts from 00 again. . Keep looping like this.

test.sh content:

#	seq -w 0 49 | xargs -n 5 > 1.txt
#!/bin/bash
#1.txt 内容为 seq -w 0 49 | xargs -n 5
currPath=/root/shellDir/program/testFile/1.txt
lineNum=`seq -w 0 49 | xargs -n 5 | wc -l`
IFS=$'\n'
#set -x

indexNum=0
for i in  `cat $currPath`
do
        #echo $i
        arrayA[$indexNum]=$i
        let indexNum+=1
done

#echo ${arrayA[*]}
count=1
while [ 1 ]
do
        echo ${
    
    arrayA[$((count-1))]}
        let count+=1
        sleep 1s

        if [ $count -gt 10 ];then
                count=1
                echo -e "\n\n num reset...."
        fi
done
	

Running results
Insert picture description here
Other ways of thinking with brother:
1.
Insert picture description here

2、

用定时任务加一个临时文件,文件里写满00到49,定时任务每次从里面读5行,顺便把读读到的5行去掉并追加到文件尾部

Four, jot instruction

jot source package:
https://launchpad.net/ubuntu/+archive/primary/+sourcefiles/athena-jot/9.0-7/athena-jot_9.0.orig.tar.gz

Jot is similar to seq, but it is more convenient in some places
Insert picture description here
Insert picture description here
. The above figure can be written as:
Insert picture description here
expand more things than seq, list letters in order and
Insert picture description here
arithmetic sequence
Insert picture description here
from -1 to 1, evenly divided into 11 parts
Insert picture description here

5. How to sort from small to large according to the number in front of'-'

1-aa
2-sa
3-aad
41-aac
55-qa
61-aa
7-qa
8-aa
9-aa
12-bb
15-vv
``
解法1  sort:
```shell
sort -t"-" -k1 -n 2.txt

Insert picture description here
Solution 2 awk:
Insert picture description here

Guess you like

Origin blog.csdn.net/Nightwish5/article/details/110850333