I have a lot of data I'm trying to split in CSV. My source data has this format:
* USER 'field1' '[email protected]' 'field3'
* USER 'field1' '[email protected]' 'field3'
* USER 'field1' '[email protected]' 'field3'
And here's what I'm trying to get as output:
field1;[email protected];field3
field1;[email protected];field3
field1;[email protected];field3
Rules:
* USER in the begin of the line must be obviously stripped;field1 and field3 could be an email address, or can contain ';field1 could be empty ''' on the beginning and ending of the field itself.My idea was to strip * USER (sed -e 's/^* USER //' could be a starting point), then "find" the mail in "the center" field, and then catch the left side and right side into two vars. Last thing should be to strip beginning and ending ' on the vars.
Unfortunately, I don't have sed or awk knowledge at this level. Any ideas on how to achieve this?
Here an example
* USER '' '[email protected]' 'CORDINI ALBERTO'
* USER 'moglie delmonte daniele' '[email protected]' 'Anna Borghi'
* USER '' '[email protected]' 'CRAVERO ANNA MARIA'
* USER '' '[email protected]' 'D'AGOSTINO PATRIZIA'
* USER '' '[email protected]' 'DE PRA' PIERO'
* USER '' '[email protected]' 'D'INGEO VIVIANA'
Update: You can use this awk for the provided input:
awk -F " '" '{gsub(/^ +| +$/, "", $3);
s=sprintf("%s;%s;%s;", $2,$3,$4); gsub(/'"'"';/, ";", s); print s}' file
;[email protected];CORDINI ALBERTO;
moglie delmonte daniele;[email protected];Anna Borghi;
;[email protected];CRAVERO ANNA MARIA;
;[email protected];D'AGOSTINO PATRIZIA;
;[email protected];DE PRA' PIERO;
;[email protected];D'INGEO VIVIANA;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With