Currently I am self learning awk and sed. I found the online book Sed & Awk 101 hacks which I found very good so far. Nevertheless, I came across I haven't continue for a few days because I can't get the concept "grouping" Here is the input file
cat employee.txt 101,John Doe,CEO 102,Jason Smith,IT Manager 103,Raj Reddy,Sysadmin 104,Anand Ram,Developer 105,Jane Miller,Sales Manager The book sed command is the following:
sed 's/\([^,]*\).*/\1/g' employee.txt The output of this command is:
101 102 103 104 105 I have tried to understand that command but it doesn't make sense to me. Then, after checking the sed documentation (man sed) I noticed that when the flag -E is not used then the regular expression takes the BRE syntax. Could you tell me why this expression doesn't work to get the same input?
sed -E 's/^(\d+),.+/\1/g' employee.txt Thanks in advance!