File read in shell scripting




















One can argue that character is better, someone can argue that word by word is better and others might stand with line. Each have their own interpretation and significance when it comes to reading. If the data in the file is huge, we would prefer going through the file line by line, in case it has a smaller number of words we can prefer going either word by word or character by character depending on the usability.

In most of the common scenarios, it is preferred to read line by line. Here we will see what kind of loops can be used for reading a file. There are eventually 2 loops through which it is possible to read a file. The concepts of loop are to implement these repetitive task through code and create powerful constructs through codes without any human intervention.

In the for loop, the initialization, condition check all happens in the syntax of the for loop itself. In the while loop, if we have to read a file, we would need to use a keyword read and hence this while is known as read while loop. The main charismatic property is the ability to read line by line when you use the keyword read.

The initialization is outside the while loop and that is the point of difference between for loop and read while loop. Both these loops are used keeping in mind the usability, and comfortableness of a developer to use any of the loops. You can use these commands with any shell. In case you use any of the above shell scripts with other shell, please update the first line to point to the right shell.

Your email address will not be published. Save my name, email, and website in this browser for the next time I comment. Toggle navigation. Related posts:. How to Install OpenOffice in Ubuntu. How to Schedule Shutdown in Ubuntu Linux. Recommended Articles. Article Contributed By :. Easy Normal Medium Hard Expert. Writing code in comment? Please use ide. Load Comments. What's New. Most popular in Linux-Unix. More related articles in Linux-Unix.

We use cookies to ensure you have the best browsing experience on our website. Start Your Coding Journey Now!



0コメント

  • 1000 / 1000