While the loop how to read from the second line of a text file

I have tried everything in the last 2 hours to get this working, but my experience in shell and programming is limited.

I have a loop

while IFS="," read var1 var2 var3 var4 var5 ; do statements here... done < $file 

Now the operator of the internal operation should read from a text file that has 5 fields, as you can see, and then use them to create Linux accounts using bash

useradd $var1 -p var2 -g var3 etc.

I want the script to start reading only from the second line, I cannot get it to work. something like while ifs =, read (from the second line) var 1 var 2 var3, etc.

the reason for this is because the file is an exported database from excel to csv, so the first line will contain headers such as name and name, etc. etc. and not needed.

Your help is appreciated.

Addition:

Before creating users, I added an if statement, and if users satisfy the condition, they will be created.

 if [ "$var5" == "fullyenrolled" ]; then continue with account creation... echo "$var1 successfuly created" else echo "Sorry user $var1 is not fully enrolled" fi 

echo output is something like

 Full name is not fully enrolled user1 successfuly created user2 successfuly created 

even if I add sed 1d | while IFS = etc. etc. it seems that he is still reading the first line, so im gets the first result, for example, "full name is not fully registered"

+8
bash
source share
2 answers

Use sed to "remove" the first line from the input passed to the while loop

 sed 1d $file | while ... do your statements here done 
+12
source share

A solution using awk :

 awk 'NR >= 2 { print }' < "$file" 
0
source share

All Articles