I'm one. I try to store the content of the csv file in the variable with bash. Every time there is a coma which I would like to create a new variable
The .ccv file looks like this:
2015-03-17, Soccer, 15: 00: 00: 30: 00
2015-03-18, Basketball, 21: 00: 00: 22: 00: 00
I would like to store the date in one variable, description (in soccer ..) in another variable, each hour in a different variable At the end, I will have 4 variables in line $ (& lt; filename) var1 = $ (cut-d, -f1 filename) var2 = $ (cut - D, -f2 filename) var3 = $ (cut -d) , -f3 filename) var4 = $ (cut -d, -f4 filename) "$ var1" echoed out
But the output looks like this:
< Code> 2015-03-17 2015-03-18 Soccer Basketball 15:00 : 00 21:00:00 15:30:00 22:00:00
But I want something like this:
2015-03-17 soccer 15:00:00 15:30:00 2015-03-18 Basketball 21: 00: 00 22:00:00
This helps me save the output of each column in a column Will meet
I also tried with awk
filename-awk -F ","' {print $ 4} 'has been filtered out
but only the first line
Thank you for your help.
You can do this as:
while IFS =, read -r date activity starts If the internal field separator variable IFS
is set to make comma If you do, different expressions from each comma will be considered as a new variable. Then you can put these variables in the loop during the time of reading in the file
No comments:
Post a Comment