Linux shell reads files by row,

Source: Internet
Author: User

Linux shell 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 



 

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.