Parse CSV in bash and assign variables

后端 未结 3 1237
耶瑟儿~
耶瑟儿~ 2021-01-03 07:39

I have a csv of the format (Working on Bash on linux)

DN , MAC , Partition ,  

123 , abc , xyz  
321 , asd , asd 

I am able to parse it u

3条回答
  •  萌比男神i
    2021-01-03 08:00

    Try a loop:

    while IFS=, read dn mac partition
    do 
      echo "Do something with $dn   $mac and $partition"
    done < file
    

    To select a record you could use a case statement:

    P2=123
    while IFS=, read dn mac partition
    do 
      case $dn in
        ($P2) echo echo "Do something with $dn   $mac and $partition" ;;
        (*)   echo "Do nothing" ;;
      esac
    done < file
    

提交回复
热议问题