in reply to Data format - delete parts of string and replace strings that match characters partly with numbers.

For the first part, this should do the job:

perl -pe"s[&[0-9&]+][]g" infile >outfile

For the second part, this might work (assumes the file is comma delimited. Requires a minor change if it is space or tab delimited):

perl -pe"s[,([^,]*HCR.*$][1]; s[,([^,]*LCR.*$][2]; " infile >outfile

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re: Data format - delete parts of string and replace strings that match characters partly with numbers.
  • Select or Download Code