[RndTbl] Another RE problem with sed
Dan Martin
ummar143 at cc.umanitoba.ca
Wed May 9 20:38:37 CDT 2007
I tried to use a sed command to extract alphanumberic names, one per
line, from a file which also included comments (line starts with '#')
and blank lines. I wanted to refer to each in a loop.
I tried
for MACHINE in `sed '/^[0-9A-Za-z][0-9A-Za-z]*/'
~/MPI-SRC/machine_names.txt`
a little awkward because sed has no '+' to indicate "at least one
alphanumeric".
I got an error that there was no command given to sed. I thought it
printed by default.
I tried
for MACHINE in `sed '/^[0-9A-Za-z][0-9A-Za-z]*/p'
~/MPI-SRC/machine_names.txt`
and it printed all the names twice.
Finally, I had to use
for MACHINE in `sed -n '/^[0-9A-Za-z][0-9A-Za-z]*/p' ~/MPI-SRC/machine_names.txt`
to suppress one copy.
Why do I get "double or nothing"?
--
-Dan
Dr. Dan Martin, MD, CCFP, BSc, BCSc (Hon)
GP Hospital Practitioner
Computer Science grad student
ummar143 at cc.umanitoba.ca
(204) 831-1746
answering machine always on
More information about the Roundtable
mailing list