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

Use 'print' but suppress line break? 1

Status
Not open for further replies.

paulobrads

Programmer
Jul 13, 2006
28
GB
I have an awk command similar to this:

Code:
echo this is a hello world | awk '{ for(i=3; i<=NF; i++){ print $i }}'

So as to print the final 3 words of the string - however print puts a line break after each one so I get:

Code:
a
hello
world

How do I suppress this so I get it all on one line?

Cheers.
 
Hi

Code:
echo this is a hello world | awk [red]-vORS=[/red] '{ for(i=3; i<=NF; i++){ print $i }}'

[gray]# or[/gray]

echo this is a hello world | awk '{ for(i=3; i<=NF; i++){ print[red]f "%s",[/red]$i }}'

Feherke.
 
print the final 3 words
Code:
echo this is a hello world | awk '{for(i=NF-2;i<=NF;++i) printf "%s ",$i;printf "\n"}'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top