linuxscrew.com linuxscrew.com

Concatenate Strings in Bash/Shell Scripts, With Examples

Here’s a short article on concatenating (merging) strings in Bash – the right way. Examples included. There are various ways two or more strings could be joined in a shell script. Various programs will accept strings and return them merged/concatenated – but using the side-effect of a programs operation to concatenate strings is a bit of a waste of time, so this article will focus on the simplest, most readable method. Inserting...

programmer group

Use shell script to insert a record every 100 rows, and the first column of the record contains the row number, while the other columns remain unchanged

1. Example: insert a record every 100 rows, and the first column of this record contains the row number, 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 line of the file do #echo "$line" Result = ` echo "$line" | cut - F2 - '; by default, it is divided by tab to get the second column to the last column Cat a.txt | awk 'NR% 100 = = 0...

programmer group

Summary of the method of judging the inclusion relation of string with shell

preface Now every time you analyze the website log, you need to judge whether Baidu spider is a real spider. After NSLOOKUP, you need to judge whether the result contains the “Baidu” string Here are some methods to determine the inclusion of strings in the shell, from the programmer’s question and answer website stackoverflow and segment fault. Method 1: using grep to search strA="long...

programmer group

Output of "time" command in shell (bash)

preface I believe we all know that time under Bash is a very useful command. It can time the execution of a script or a program, which is usually very convenient when roughly comparing the execution efficiency of a program. However, you will find that the time text output by the time command cannot be simply redirected, for example, to a text file, which can only be displayed on the screen, which is very inconvenient for non...