Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

Shell read file line by line

while read line; do    
    echo $line    
done < file.txt
Comment

read lines bash script


# Let's use a text file called file.txt
# the file contains 5 lines of some programming languages in use today:

$ cat file.txt
#Output:
#	JavaScript
#	Java
#	C
#	Python
#	C#


# Method 1 'wc'
# 'wc' command can be used to find the number of lines, characters,
# words, and bytes of a file.

$ wc -l file.txt

# Or

$ wc -l < file.txt

# Or

$ wc -l file.txt

# Output:
#	10 file.txt

# OR

# Method 2 - 'sed'
# 'sed' is a stream editor that can be used to perform basic text transformation 
# of an input file.
# This command is mostly used for find-and-replace functionality and 
# can also be used to find the number of lines of a specified file.

$ sed -n '=' file.txt
# Output:
#	1
#	2
#	3
#	4
#	5

# Or 

# sed -n '$='  which gives the overall number of lines
$ sed -n '$=' file.txt
# Output:
#	5

Comment

use lines from file for bash command

xargs -I{} curl "xyz.com/v1/"{} <file
Comment

PREVIOUS NEXT
Code Example
Shell :: git checkout -f 
Shell :: ubuntu chang host name 
Shell :: difference between rebase and merge in git 
Shell :: ubuntu iso 
Shell :: mdem ubuntu ssh key 
Shell :: sum of output unix 
Shell :: ubuntu add multiverse 
Shell :: how to enable ssh on headless raspberry pi 
Shell :: setup teamspeak docker 
Shell :: powershell redirect output to null 
Shell :: sbatch: error: Batch script contains DOS line breaks ( ) sbatch: error: instead of expected UNIX line breaks ( ). 
Shell :: download powershell 7.2.1 
Shell :: create .pem file from crt 
Shell :: how to find all the execution policies 
Shell :: sound output raspberry pi 
Shell :: pip upgrade version 
Shell :: tail remove newline 
Shell :: zsh increment variable 
Shell :: conda install gdal 
Shell :: homebrew without sudo mac 
Shell :: Git command to Change Your Committer Name & Email Globally 
Shell :: install nodejs 16 on ubuntu 
Shell :: git how to add remote 
Shell :: push an existing git repository 
Shell :: windows start shortcut cmd administrator 
Shell :: command to list hardware in linux 
Shell :: compare repositories github 
Shell :: create user with group 
Shell :: git edit user of last commit 
Shell :: create file in linux using cat 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =