Bash - Reading csv delimited file to array and for further manipulation
Hello,
I am trying to do this: 1. Read csv delimited file line1 and store all values in array 2. Use the values stored in the array and replace values in other text file with them 3. read line2 in the cvs file and repeat the process 4. Do above for all lines in the cvs file for example: file1.cvs content: text1,text2,text3,"text 4" a1,a2,3,"a 4" file.txt content: some text $array1$ some text some text $array2$ some text 1. read line 1 - text1,text2,text3,"text 4" put each value in array X[] lines that contain spaces in cvs will have double quotes 2. read x[1] and replace value $array1$ (in file.txt) with x[1] read x[2] and replace value $array2$ (in file.txt) with x[2] and so on Can above be accomplished in BASH and how? |
I created below script:
#!/bin/bash while IFS=, read ext password name do echo "ext -> [${ext}]" echo "password -> [${password}]" echo "name -> [${name}]" rm -f filetemp cp basefile filetemp sed -i 's/#ext#/'"${ext}"'/g' filetemp sed -i 's/#password#/'"${password}"'/g' filetemp sed -i 's/#name#/'"${name}"'/g' filetemp mv filetemp "${ext}filetemp" done < input anyone can think of something better? |
All times are GMT -5. The time now is 07:18 PM. |