Linked Questions
133 questions linked to/from Looping through the content of a file in Bash
1001 votes
10 answers
2.2m views
Read a file line by line assigning the value to a variable [duplicate]
I have the following .txt file: Marco Paolo Antonio I want to read it line-by-line, and for each line I want to assign a .txt line value to a variable. Supposing my variable is $name, the flow is: ...
32 votes
5 answers
130k views
How do I iterate through lines in an external file with shell? [duplicate]
I have one file with a list of names. I need to loop through all names in this file from an external file with a shell script. How can I do that? Example files: scripts/names.txt alison barb charlie ...
4 votes
3 answers
110k views
Reading files line by line in by using for loop bash script [duplicate]
Say for example I have a file called "tests",it contains a b c d I'm trying to read this file line by line and it should output a b c d I create a bash script called "read" and try to read this file ...
0 votes
1 answer
4k views
for loop with multiple commands [duplicate]
I have multiple filenames in files.txt. I want to run three scripts on each file. I my suggestion correct? files.txt: SRR13143.sra SRR44234.sra SRR23424.sra my try: for FILE in "file.txt"; do ...
-1 votes
2 answers
2k views
while read line in a file from a specific column [duplicate]
Just need some help with a while read file from a specific column I have a file with a few columns and I want to use while loop for a specific column 123 50012 1111 235 40023 2222 674 30021 3333 ...
0 votes
1 answer
3k views
How to use for loop to pass a line of string from text file as separate variable for another script in Bash [duplicate]
I am writing a bash script that accepts a manifest.txt file. It should cycle through each row of that text file and call another script to pass the text string from the row of the text file after ...
1 vote
1 answer
2k views
how to loop over pattern from a file with grep [duplicate]
I am trying to grep a series of patterns that are, one per line, in a text file (list.txt), to find how many matches there are of each pattern in the target file (file1). The target file looks like ...
0 votes
1 answer
1k views
How to do a loop through two columns in bash linux [duplicate]
I'm new in bash linux coding. Basically I would like to do a loop using a text file with two columns. For a single column file I use this type of code: for element in `cat /path/file.txt | tr -d '\r'` ...
-2 votes
3 answers
551 views
Create a stack of folders named from a .txt file [duplicate]
I have a one column text file (dates.txt) and I want to create a stack of directories named after the dates elements. How can I interpret it in bash?
0 votes
0 answers
1k views
What does "done <<< $(cat $1)" do? [duplicate]
I have a program that counts lines containing alphanumeric words. For example: this is line1 this is line 1234 this is line4 The answer is 2. count=0 while IFS= read -r line do if [[ $line =~ [[...
-1 votes
1 answer
318 views
In a bash script, how do I reference a separate file to use it in a for loop? [duplicate]
I am trying to make a checkpoint management script, which will delete all checkpoints that are over 3 days old for a variety of databases. I want to keep the code in one script and then keep a list of ...
1 vote
1 answer
268 views
In bash script how do I reference a file as the input for an interactive prompt [duplicate]
Absolute beginner here. I have a list of passwords in a file named "pw.prn". Welcome99 ABCDEFGH 12545678 lakers2021 gododgers I wish to run each line in the file against a hashing program (...
-1 votes
1 answer
420 views
I need a script to replace old libraries with newer library in all files [duplicate]
I have numerous files in a directory and want to replace one of the libraries used in all of these files with a newer library because the old library no longer works. I have used ls > names.txt to ...
0 votes
1 answer
393 views
Bash how to loop through the output of a command and assign that output to variable [duplicate]
I have a for loop in my bash script. for dir in $directories do dockerfile=$(find ./repo/$dir -name "Dockerfile"); docker build -f $dockerfile . -t $dir:version; ...
0 votes
1 answer
300 views
How to read parameter from .txt file in bash [duplicate]
I want to use an nmap script to convert ASN -> IP ranges So the nmap script is used like that, nmap --script targets-asn --script-args ragets-asn.asn=12345 This command return the IP ranges in ...