Computing.Net > Forums > Unix > field sperating with awk

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.

field sperating with awk

Reply to Message Icon

Name: salem
Date: January 7, 2007 at 20:10:37 Pacific
OS: hpux
CPU/Ram: 4GB
Product: hp9000
Comment:

Hello

echo hello1 192.168.1.9|awk 'BEGIN { FS = "." } ; { print $1"."$2"."$3}'
hello1 192.168.1

I only need to pring the first three octats from the second field and delete the first field (hello1).

The echo string is an output from a loop.

Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: rais
Date: January 8, 2007 at 10:30:47 Pacific
Reply:

You can do:

echo "hello1 192.168.1.9" | awk '{print $2}' | awk -F. '{ print $1"."$2"."$3}'

Thanks.


0

Response Number 2
Name: salem
Date: January 8, 2007 at 10:38:40 Pacific
Reply:

I already have this in my script, I would like to change it to one line instead of a pipe to another awk statement?



0

Response Number 3
Name: James Boothe
Date: January 9, 2007 at 08:25:30 Pacific
Reply:

echo hello1 192.168.1.9|awk 'BEGIN {FS="[. ]"};{print $2 "." $3 "." $4}'

192.168.1

Above, I set Field Separator to either a dot or a space. But one warning: The default field separation of white space allows any number of consecutive spaces/tabs to count as a single separator. But when setting FS like this, multiple consecutive spaces will be taken as multiple separators, so this can mess you up with additional null fields.

And that is why I did not use the quotes on my echo command. The presence of quotes would preserve the extra spaces, but without the quotes, echo will output each operand with only one space between.


0

Response Number 4
Name: salem
Date: January 12, 2007 at 07:27:26 Pacific
Reply:

Thanks alot!!!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Finding idle time of a pr... awk return value



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: field sperating with awk

Printing with AWK Utility www.computing.net/answers/unix/printing-with-awk-utility/6219.html

please help me with awk, please www.computing.net/answers/unix/please-help-me-with-awk-please/3813.html

find the number of line with awk. www.computing.net/answers/unix/find-the-number-of-line-with-awk/4554.html