|
|
Subject:
AWK adds extra spaces
Category: Computers > Algorithms Asked by: questioner1234-ga List Price: $5.00 |
Posted:
29 Oct 2003 11:36 PST
Expires: 28 Nov 2003 11:36 PST Question ID: 270836 |
AWK is inserting spaces in this: Price: $",$2,$7, So instead of "Price: $10" it outputs "Price: $ 10" the database is tab-delimited and doesn't appear to have extra spaces. Here is the whole awk: BEGIN { FS = "\t" } {print "<html>\n<head>\n<title>",$1,"</title>\n</head>\n<body>\n", "\<\!--webbot bot=\"Include\" U-Include=\"../top.htm\" TAG=\"BODY\" --\>\n<table>\n<tr>\n<td width=\"200\" valign=\"top\">\n", "\<\!--webbot bot=\"Include\" U-Include=\"../left-nav.htm\" TAG=\"BODY\" --\><p> </td>\n", "<td valign=\"top\">\n<h1>",$1,"</h1>\n", "<img src=\"",$5,"\"><br>Price: $",$2,$7, "<a href=\"",$6,"\">Order Now</a>","\n",$6,"\n", "</td>\n</tr>\n</table>\n</body>\n</html>\n" > $4} |
|
Subject:
Re: AWK adds extra spaces
Answered By: maniac-ga on 29 Oct 2003 17:34 PST Rated: |
Hello Questioner1234, By default, the results of the print command in awk are separated by - output field separators (between each argument to print) - record field separators (between each input record processed). The default output field separator (OFS) is a space. Add {OFS=""} to your awk script if you want no characters between field output. For example, I created the awk script... (a.awk) {OFS=""} {FS="\t"} {print $1,$2,$3} and the text file (a.txt) 1 a cat 2 b dog 3 c horse and processed with awk -f a.awk a.txt to get 1acat 2bdog 3chorse For more information, see the man page for awk... http://unixhelp.ed.ac.uk/CGI/man-cgi?awk http://campuscgi.princeton.edu/man?awk or output of man awk on your system. --Maniac |
questioner1234-ga
rated this answer:
excellent answer and explanation |
|
There are no comments at this time. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |