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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

line # problem

Status
Not open for further replies.

desanti

Programmer
Jul 9, 2004
51
US
a simple pgm but!!!!
{if ($NF ~ /0-9/) #this is o.k
print($0,"\r"} #this is o.k.
else
print($0,"\t\t\t\t\t# ",FNR,"\r"} #see below.
}
this pgm works fine EXCEPT it will not put a line number(FNR) or # on the print statement with the tabs.it will
put the FNR before and after but not on that line.what don't i see??thank you.
 

Comments on your code:

[tt]if ($NF ~ /0-9/)[/tt]
If you're trying to match a numeral, the regular expression should be [tt]/[0-9]/[/tt].

[tt]print($0,"\r"}[/tt]

Of course, this should end with ), not }.
Apparently, the [tt]"\r"[/tt] is there to cause a line
feed. [tt]print[/tt] produces a line feed by default.
If you actually want an extra linefeed, use [tt]"\n"[/tt].
[tt]\r[/tt] simply moves the cursor to the beginning of the current line.

Code:
{ if ( $NF ~ /[0-9]/ )
    print $0
  else
    print $0 "\t\t\t\t\t# " FNR
}
 
futurelet: thanx for input.the code i have is as you showed
i just mis-keyed.i use "\r" because i am using a dos command line.
 
When you post your code, it would be better to copy and paste it than to type it; that way we will see the exact program that you running, and you'll save time.

Whether or not you're using a dos command line,
[tt]
print $0 "\r"
[/tt]and[tt]
print $0
[/tt]
produce the same result.

When using Awk, don't separate the arguments to the print command with "," unless you want a space (actually, OFS) between them.
[tt]print "hel", "lo"
hel lo
print "hel" "lo"
hello
[/tt]

I would suggest that you post your code again by copying and pasting, so that we can see the exact same program that you are running.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top