Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sort routine

Status
Not open for further replies.

sort

Technical User
Jan 22, 2000
2
NL
how can i write a routine, lets say show, that reads several files, grap the string i give than give th output the following way:<br>
<br>
show a<br>
a<br>
just some tekst<br>
like this<br>
awk<br>
a tekst routine<br>
you must be able to work with<br>
<br>
In the file the tekst is like this:<br>
a,just some tekst<br>
a,like this<br>
awk,you must be able to work with<br>
awk,a tekst routine<br>
<br>
As You see the tekst is spitted in two part delimmeted by a &quot;,&quot;. The files al end with txt<br>
<br>
I started with:<br>
grep -i $1 /home/mydir/doc/showdir/*.txt¦sort<br>
<br>
This example give the output sorted but not displayd as i want. The right way is<br>
print $1<br>
go to the next line<br>
print &quot;\t&quot;$2<br>
read next input line<br>
if $1 == previous $1 print &quot;/t&quot; $2<br>
if $1 !== previous $1 print $1<br>
&quot;/t&quot; $2<br>
end routine<br>
<br>
If anyone can help me please respond to:<br>
<A HREF="mailto:w.alsemgeest@hccnet.nl">w.alsemgeest@hccnet.nl</A><br>
or<br>
<A HREF="mailto:w.l.alsemgeest@ptt-post.nl">w.l.alsemgeest@ptt-post.nl</A><br>

 
<br>This is some code (slightly modified) right<br>out of &quot;The AWK Programming Language&quot; book<br>on page 126 that seems to do what you want.<br><br>You can use it like this:<br><br><br>cat /home/mydir/doc/showdir/*.txt ¦ tekst &gt; outfile<br><br><br>file: tekst (make executable)<br><br><br><br><br>sort ¦\<br><br>awk 'BEGIN{FS=&quot;,&quot;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;$1 != prev {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (NR &gt; 1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;\n&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prev = $1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;%s\n\t%s\n&quot;, $1, $2)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;next<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ printf(&quot;\t%s&quot;, $2) }<br><br>END { if (NR &gt;1) printf(&quot;\n&quot;) }'<br><br><br>I hope this helps you! <p>flogrr<br><a href=mailto:flogr@yahoo.com>flogr@yahoo.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top