1. Example: Insert a record every 100 rows, and the first column of this record contains the line number, and the other columns are the same as the first row
#!/bin/sh
var= "00001" # variable
cat A.txt|awk ' nr==1 ' |while read Line # Get the first row of the file do
#echo "$line"
result= ' Echo ' $line ' |cut-f2-' # Defaults to tab split to get the second column to the last column of
cat A.txt|awk ' nr%100==0{printf ("%04d\n", NR)} ' |while Read line # Get the line number every 100 lines, the line number is 4 bits, the insufficient digits complement 0 do
data= ' echo-e ' 9$line$var\t$result ' "
echo" $line "
#echo" $result "
#echo "$data"
#sed-E "' $line ' a\ ' $data '" a.txt
sed-i ' $line ' a ' "$data" ' A.txt # Insert
done to file Done
2, example: Every 100 lines, replace the 100th row of data
#!/bin/sh
var= "abc"
Cat A.txt|awk ' nr%100==0 ' |awk ' {split ($0,b, "T");p rint b[2]} ' |while read line # reads a file, Get the second column of the current row
#echo "$line"
sed-i "s/$line/$var/g" A.txt # every 100 rows replaces the obtained column with known variables done
The above is a small set for you to introduce the use of shell script to achieve every 100 rows inserted a record and record the first column contains row number other columns unchanged, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!