Answer the question
In order to leave comments, you need to log in
Bash line by line reading csv lines via while read line?
Hello, I have not been studying for a long time, but I urgently need to somehow build a code for line-by-line reading of csv lines through while read line.
Let's say I have a Data.csv file and it contains names and data.
I would like to create something that would read a data cell through a line and assign a variable, for example $name1
Then I know how to use everything, I almost don’t have enough knowledge on this, I turn to the GURU))))
Answer the question
In order to leave comments, you need to log in
IFS=$'\n'
set -f
for line in file
do
... $line
done
Found this option
cat /home/uzer/Name.csv | while read line
do
echo $line | cut -d ' ' -f1 #1-name
done
But the problem is that everything is displayed in a compartment, and you need to separately have a separator "," but putting it in -d is displayed as usual, who can tell me or did I misunderstand something?
All the same, I found a way out)
while read -r line
do
IFS=","
set -- $line
username=$1
username2=$2
done < Name.csv
And separates and gives each line its own variable.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question