I have a file with this format:
any_ascii_chars_except_comma,any_ascii_chars_except_comma,xxx
xxx is a 3 numeric string (examples are 001, 024, 057). What I want to do is split my original file into a series of files called (for example) 001.txt, 024.txt, 057.txt - where the record goes into the file named by the value of the 3rd field. How can I do this? I've tried:
grep ^[\ -\+\--\~],[\ -\+\--\~],001 <my_file> > 001.txt
grep ^[\ -\+\--\~],[\ -\+\--\~],024 <my_file> > 024.txt
grep ^[\ -\+\--\~],[\ -\+\--\~],057 <my_file> > 057.txt
and so on (there's a space after the first backslash within the brackets). My thinking was that the comma is between the plus sign (+) and the hyphen (-) in the ASCII sequence so I thought I could grep for all chars either side of the comma with this syntax. But it doesn't work. I've tried removing & adding backslash chars with no joy.
Hope this makes sense to you all - can anyone help? I bet the answer is something much simpler than this
TIA Chris
any_ascii_chars_except_comma,any_ascii_chars_except_comma,xxx
xxx is a 3 numeric string (examples are 001, 024, 057). What I want to do is split my original file into a series of files called (for example) 001.txt, 024.txt, 057.txt - where the record goes into the file named by the value of the 3rd field. How can I do this? I've tried:
grep ^[\ -\+\--\~],[\ -\+\--\~],001 <my_file> > 001.txt
grep ^[\ -\+\--\~],[\ -\+\--\~],024 <my_file> > 024.txt
grep ^[\ -\+\--\~],[\ -\+\--\~],057 <my_file> > 057.txt
and so on (there's a space after the first backslash within the brackets). My thinking was that the comma is between the plus sign (+) and the hyphen (-) in the ASCII sequence so I thought I could grep for all chars either side of the comma with this syntax. But it doesn't work. I've tried removing & adding backslash chars with no joy.
Hope this makes sense to you all - can anyone help? I bet the answer is something much simpler than this
TIA Chris