Linux shell read file by line processing

Source: Internet
Author: User

One way is to useCatand anti-quote

PS: Anti-quotes play the role of command substitution in Linux. Command substitution refers to the ability of the shell to interpolate the standard output of a command anywhere on a command line.

The input format is as follows:

20151207 [email protected]. com
20151225 155581558905678

As follows

The internal field delimiter (Internal field Separator, IFS) is an important concept in shell scripting. IFS is an environment variable that stores delimiters. It is the default bounding string used by the current shell environment, for example:    data= "name, sex, Rollno, location"    #我们可以使用IFS读取变量中的每一个条目    oldifs= $IFS    IFS = "," for    item in $data    does         echo item: $item    done    ifs= $oldIFS


Count=0for line in ' Cat Data.txt ' does  ifs=$ ' for  value in $line do   count=$[$count +1]    echo $ Value     Done#echo $linedone

one is to use a pipe or redirect

' | ' Represents a pipe connection, and a pipeline in Linux is a special file descriptor.

Pipeline is a very important way of communication in Linux, is to connect the output of one program directly to the input of another program, often said pipe refers to the nameless pipe, the nameless pipe can only be used in the relationship between the process, which is its most important difference with the famous pipe.
A well-known pipe called Named pipe or FIFO (first-in, in-out) can be created with function Mkfifo ().

# second Examplecat data.txt |  While read Linedo-var in $line do   



Linux shell read file by line processing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.