Regular expression in grep -E | awk print

Hi All,

I have file.txt with contents like this:

random text
To: recipient@email.co.uk
<HTML>S7randomtext more random text
random text
To: recip@smtpemail.com
<HTML>E5randomtext more random text
random text
I need the output to look like this:

1,,,1,S7
1,,,1,E5

My code so far is:

 
grep -E "[A-Z][0-9]" file.txt | awk '{print ",1,,,1,"[A-Z][0-9]}' > out.txt

but I get this error: awk: line 1: syntax error at or near [

How can I get the Regular Expression [A-Z][0-9] into the print of awk??? Please help asap

echo '<HTML>S7randomtext' | sed 's#.*>\([A-Z][0-9]\).*#1,,,1,\1#'

Thanks, but would this work (this is a snippet of a much much larger script):

grep -E "[A-Z][0-9]" file.txt | sed 's#.*>\([A-Z][0-9]\).*#1,,,1,\1#' > out.txt

Hello friends, could you please tell me what does " > " stands for in SED part of the script? I understand all the regex except it,

regards

you don't need 'grep' if you're using 'sed':

sed '/[A-Z][0-9]/ s#.*>\([A-Z][0-9]\).*#1,,,1,\1#' file.txt > out.txt

It's a literal > (meaning match a greater-than sign, or in this context an angled bracket)

It's not part of an RE. Look at the original pattern:

echo '<HTML>S7randomtext' | sed 's#.*>\([A-Z][0-9]\).*#1,,,1,\1#'
 awk '/^<HTML>[A-Z][0-9]/ { printf "1,,,1,%s\n", substr($0,7,2) }' file.txt
sed -n 's/^<HTML>\([A-Z][0-9]\).*/1,,,1,\1/p' file.txt

Hi Again!

Here is an extended part of the script... I'd like to be sure that sed will work instead of grep....

grep -l "search string in files I want" smtp*.tmp > email_filenames_list.txt ;
cat email_filenames_list.txt | xargs cat >> smtp_all_emails_logs.txt ;
sed '/[A-Z][0-9]/ s#.*>\([A-Z][0-9]\).*#,1,,,1,\1#' smtp_all_emails_logs.log > out.txt ;
grep "^To" smtp_all_emails_logs.txt | awk '{print ","$2}' > recipients.txt ;
paste out.txt recipients.txt

the grep line definately works, but would sed run through a massive list of emails that have all been put in one file (smtp_all_email_logs.txt) and print:
S7,1,,,1,recipient@email.co.uk
R2,1,,,1,recip@smtpemail.com
etc in AIX environment

Another quick question: how can I stop a carrage return/line feed being included after the recipients email address? Cause it's screwing up my spreadsheet.