Computing.Net > Forums > Unix > awk in shell script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

awk in shell script

Reply to Message Icon

Name: schauan
Date: April 29, 2004 at 06:33:06 Pacific
OS: HPUX 10.20
CPU/Ram: Risc / 128
Comment:

Hello,
I want to give back the first 3 letters of my hostname to a variable in a shell script like this principle:
N=awk'{printf substr(`uname -n`,1,3) };{exit}'
but so it doesn't work. I have one error:
The statement `uname -n`cannot be correctly parsed.
If I put my hostname in this line my variable havn't any result, and if I take only the awk-command I must press enter to finish it ... Can me help everyone, please?
andre


regards everybody,
andre



Sponsored Link
Ads by Google

Response Number 1
Name: Wolfbone
Date: April 29, 2004 at 07:11:42 Pacific
Reply:

N=$(uname -n | cut -c-3)


0

Response Number 2
Name: schauan
Date: April 29, 2004 at 11:21:17 Pacific
Reply:

Hello Wolfbone,
thanks for your answer, I think, I was a little bit blind today. It's so easy with cut and I thought, cut is only for tables ... And that I can't take every UNIX-command in awk - must pipe it to awk - I know also - sometimes ;-)
But can you give me an answer of the second problem - press Enter to finish? p.e. I write
awk'{printf substr(myname,1,3) }; {exit}'
at the command line, then I press Enter and on screen I have a blank line. Then I press a second time Enter, and now I see the result
myn#
regards and thanks, schauan


regards everybody,
andre


0

Response Number 3
Name: Wolfbone
Date: April 29, 2004 at 11:59:52 Pacific
Reply:

Awk was looking for some input - you didn't give it a file so it opened stdin and waited for you to give it something.


0

Response Number 4
Name: WilliamRobertson
Date: May 1, 2004 at 08:56:31 Pacific
Reply:

In awk, the BEGIN and END sections (if present) are executed only once regardless of stdin, e.g:

awk 'BEGIN {print substr("Banana",1,3) };'

Also just for fun,

typeset -L3 N
N=$(uname -n)


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: awk in shell script

Using hex-code in shell script www.computing.net/answers/unix/using-hexcode-in-shell-script/4227.html

Awk in a script www.computing.net/answers/unix/awk-in-a-script/6027.html

loops in shell scripts!!! www.computing.net/answers/unix/loops-in-shell-scripts/5140.html