Question: I have a list of strings with the following format. What commands could I use to extract the respective sections. I was thinking of using grep to extract the keywords ie: ADD, username(atra522) etc.. 
How should I approach this problem?

```
cop1010 ADD atra522,Allison Track,CT,canada

```

I know how to use cut or awk to get all the fields by looking for the commas, but I don't know how to make it work with the first field "cop1010 ADD atra522".

Answer: 
You can use awk's `split` function to further split the first field into an array e.g.

```
echo 'cop1010 ADD atra522,Allison Track,CT,canada' | 
  awk -F, '{
    split($1,a,"[ \t]+");
    if (a[2] == "ADD") {
      printf "Adding user: %s\n", a[3];
    }
  }'

```
Python solution:

```
import re,sys;  
for l in sys.stdin:
   if 'ADD' in l:
       data = [re.split(",",l.rstrip("\n"))[0].split()[-1]]+re.split(",",l.rstrip("\n"))[1:] 
       print " ".join(data)
       data = []

```

Tested with custom file based on OP's example:

```
$ cat input.txt                                                                                                                       
cop1010 ADD atra522,Allison Track,CT,canada
some other stuff
testuser ADD test522,Allison TEST,CT,germany
$ python user_data.py < input.txt                                                                                                     
atra522 Allison Track CT canada
test522 Allison TEST CT germany

```

For python 3 compatibility and pretty printing of data, we could do something like this:

```
$ cat user_data.py                                                                                                                    
from __future__ import print_function
import re,sys;  
for l in sys.stdin:
   if 'ADD' in l:
       data = [re.split(",",l.rstrip("\n"))[0].split()[-1]]+re.split(",",l.rstrip("\n"))[1:] 
       print("Username: " + data[0])
       print("Real Name: " + data[1])
       print("Some kind of two char string: "+ data[2])
       print("Location: " + data[3])
       print("- - -")
       data = []

$ python user_data.py < input.txt                                                                                                     
Username: atra522
Real Name: Allison Track
Some kind of two char string: CT
Location: canada
- - -
Username: test522
Real Name: Allison TEST
Some kind of two char string: CT
Location: germany
- - -

```