Linuxshell reads files by row
One way is to use cat and reverse quotation marks.
Ps: reverse quotation marks play the role of command replacement in Linux. Command replacement means that shell can insert the standard output of a command to any location in a command line.
The input format is as follows:
20151207 617899182468@qq.com
20151225 155581558905678
As follows:
The Internal Field Separator (IFS) is an important concept in shell scripts. IFS is the environment variable that stores the delimiters. It is the default delimiter used by the current shell environment, for example, data = "name, sex, rollno, location "# We can use IFS to read every entry in the variable oldIFS = $ IFS =", "for item in $ data do echo Item: $ item done IFS = $ oldIFS
count=0for line in `cat data.txt`do IFS=$' ' for value in $line do count=$[$count+1] echo $value done#echo $linedone
One is to use pipelines or redirection.
'|' Indicates the Pipeline Connection. in linux, the pipeline is a special file descriptor.
Pipeline is an important communication method in Linux. It connects the output of a program directly to the input of another program. It is often said that most pipelines refer to unknown pipelines, an unknown pipeline can only be used between unrelated processes, which is the biggest difference between it and a famous Pipeline.
A famous pipeline is named pipe or FIFO (first-in-first-out). It can be created using the mkfifo () function.
# second examplecat data.txt | while read linedo for var in $line do echo $var donedone