I guess the simple answer is because you told it to...&nbsp; the p command prints the current pattern space, the -n suppress it.&nbsp; I&#39;m not sure how to use sed like grep, which is basically what you&#39;re doing :)<br><br>This may be a silly observation, but a regexp like ^[0-9A-Za-z][0-9A-Za-z]* is the same as ^[0-9A-Za-z] (with or without a + at the end) if you&#39;re looking for a simple match and not replacing anything. The second alphanum doesn&#39;t have to match at all because of the *, so there&#39;s not much point in having it!
<br><br>Quite frankly sed is too much of a pain for anything but the most simple substitutions.&nbsp; In your case I&#39;d look at egrep (which supports the + operator, previous comment notwithstanding) , and for anything more complex, a perl one liner.&nbsp; 
<br><br>sed &#39;s/something/complex/g&#39; file<br><br>is the same as<br><br>perl -pe &#39;s/something/complex/g&#39; file<br><br>and you can do a lot more things in the code.&nbsp; You can even edit a file in place with -i:<br>
<br>perl -i.bak -pe &#39;s/sed/perl -pe/&#39; myscript.sh<br><br>or only print certain lines with -n (no print rather than the -p meaning print)<br><br>perl -ne &#39;if (/\/([^\/]+$)/) { print $1; }&#39; file<br><br>(the last one should print the last component of a /path/to/file/name of lines looking like a file path, and nothing on the rest)
<br><br>Sean<br><br><div><span class="gmail_quote">On 5/9/07, <b class="gmail_sendername">Dan Martin</b> &lt;<a href="mailto:ummar143@cc.umanitoba.ca">ummar143@cc.umanitoba.ca</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I tried to use a sed command to extract alphanumberic names, one per<br>line, from a file which also included comments (line starts with &#39;#&#39;)<br>and blank lines.&nbsp;&nbsp;I wanted to refer to each in a loop.<br><br>I tried
<br>for MACHINE in `sed&nbsp;&nbsp;&#39;/^[0-9A-Za-z][0-9A-Za-z]*/&#39;<br>~/MPI-SRC/machine_names.txt`<br>a little awkward because sed has no &#39;+&#39; to indicate &quot;at least one<br>alphanumeric&quot;.<br><br>I got an error that there was no command given to sed.&nbsp;&nbsp;I thought it
<br>printed by default.<br><br>I tried<br>for MACHINE in `sed&nbsp;&nbsp;&#39;/^[0-9A-Za-z][0-9A-Za-z]*/p&#39;<br>~/MPI-SRC/machine_names.txt`<br>and it printed all the names twice.<br><br>Finally, I had to use<br><br>for MACHINE in `sed -n &#39;/^[0-9A-Za-z][0-9A-Za-z]*/p&#39; ~/MPI-SRC/machine_names.txt`
<br><br>to suppress one copy.<br><br>Why do I get &quot;double or nothing&quot;?<br><br><br>--<br>&nbsp;&nbsp;-Dan<br><br>Dr. Dan Martin, MD, CCFP, BSc, BCSc (Hon)<br><br>GP Hospital Practitioner<br>Computer Science grad student<br>
<a href="mailto:ummar143@cc.umanitoba.ca">ummar143@cc.umanitoba.ca</a><br>(204) 831-1746<br>answering machine always on<br><br>_______________________________________________<br>Roundtable mailing list<br><a href="mailto:Roundtable@muug.mb.ca">
Roundtable@muug.mb.ca</a><br><a href="http://www.muug.mb.ca/mailman/listinfo/roundtable">http://www.muug.mb.ca/mailman/listinfo/roundtable</a><br><br></blockquote></div><br><br clear="all"><br>-- <br>Sean Walberg &lt;<a href="mailto:sean@ertw.com">
sean@ertw.com</a>&gt;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://ertw.com/">http://ertw.com/</a>