consolidating rows from csv file
Hi all. I have a csv file with complete rows like this
(xxx is just random value but is needed) 0801 xxxx xxxx xxxx 0801 xxxx xxxx xxxx 0801 xxxx xxxx xxxx 0801 xxxx xxxx xxxx 0801 xxxx xxxx xxxx 0851 yyyy yyyy yyyy 0851 yyyy yyyy yyyy 0851 yyyy yyyy yyyy 0851 yyyy yyyy yyyy 0851 yyyy yyyy yyyy (xxxx values in all rows are distinct and unique, i just wrote xxx for simplicity) Now i want to consolidate all rows containing 0801 to a csv file named 0801, same with 0851 with 0851.csv file. But need to automate this process, is it possible using any builtin linux tool like awk or something ? kindly guide me |
Does this achieve what you are after:
Code:
for i in `cat input.file |cut -d" " -f1 |sort -u`; do cat input.file |grep ^$i >$i; sed -i 's/ /,/g' $i; done |
Code:
awk '{ print > $1 ".csv" }' file |
You could try
#!/bin/bash $ tr -t " " "," < input.file > output.file if grep '0801' output.file then `grep '0801' output.file` >> 0801.csv elif grep '0851' output.file `grep '0851' output.file` >> 0851.csv else echo "done" fi exit 0 |
All times are GMT -5. The time now is 01:35 PM. |