T
T
topmoneyweb2018-07-06 00:19:55
bash
topmoneyweb, 2018-07-06 00:19:55

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

2 answer(s)
C
chupasaurus, 2018-07-06
@chupasaurus

IFS=$'\n'
set -f
for line in file
do
... $line
done

This option ignores empty lines.

T
topmoneyweb, 2018-07-06
@topmoneyweb

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 question

Ask a Question

731 491 924 answers to any question