ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I would like to write a shell script that reads a text-file, reading out each line separatly in order to use each line as argument.
The Problem is that I do not know how to read each line separatly.
My file has user's names:
bob
john
chris
.....
and I would like to write a script that reads the 1st line and uses bob as argument, then the 2nd line and uses it as argument for the same command, and so on.
#!/bin/bash
# Set the field seperator to a newline
IFS="
"
# Loop through the file
for line in `cat file.txt`;do
# Echo the line (echo could be changed to whatever command you want)
echo $line
done
the code that I wrote is:
<code>
#!/bin/bash
#file = $1
count= cat $1 | wc -l
myuser=cat $1 | ?????? What should I write here to read each single line separatly and use as argument?
for i in count
do
./another_script mysuser
done
</code>
I don't know how to get just a line at a time (a line beeing a word) to save it into the variable myuser.
Great! It works fine!
I wrote the following test-script.
Code:
#!/bin/bash
# Set the field seperator to a newline
IFS="
"
# Loop through the file
for line in `cat file.txt`;do
# Echo the line (echo could be changed to whatever command you want)
echo "$line wird gelöscht" >> text2
echo "$line wurde gelöcht"
done
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.