I have this kind of table:
classA, s1, ss1
classA, s1, ss2
classA, s2, ss1
classB, s1, ss1
classB, s1, ss2
classC, s1, ss1
classC, s2, ss1
classC, s2, ss2
Which I would like to split in 3 files called “classA”, “classB”, and “classC”, according to the consecutive values in 1st column. I tried first to find a way to do that using csplit, but it seems to work only on a specified pattern, not when the pattern changes. Is there any awk way or any other command-line tool to do that?
[UPDATE]
I have also some slashes in my 1st column that lead to that error, example:
classA, s1, ss1
classA, s1, ss2
classA, s2, ss1
classB, s1, ss1
classB, s1, ss2
classC, s1, ss1
classC, s2, ss1
classC, s2, ss2
classA/classA.1/classA.2, s1, ss1
classA/classA.1/classA.2, s1, ss2
And when I run the command:
awk -F, '{ print $0 > $1}' infile
It works with until “classC” but then I have that error because I guess it interprets the “/” as a path:
fatal: can't redirect to `classA/classA.1/classA.2' (No such file or directory)
output
where $1 has “/…/path/info, try
If you don’t do the
gsub(), any ‘/’ chars will be intrepreted to follow a path to create the output file. Of course the path specfied will need to exist, or you’ll get error messages to that affect.Note that some awks prefer to have the ‘/’ char like
gsub(/[\/]/,"", fileName), or you might even need[\\/]as the search target.IHTH