Solved

splitting octets with awk

Posted on 2013-01-25
6
273 Views
Last Modified: 2013-01-27
I  have a ip address  Quad=10.20.30.40

with awk I want to print this out
10
20
30
40

awk -F.     is not working for me.
0
Comment
Question by:TIMFOX123
6 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 100 total points
Comment Utility
Quad=10.20.30.40
echo $Quad | awk -F. '{for( i=1;i<=NF; ++i){ print $i}}'
0
 
LVL 31

Assisted Solution

by:farzanj
farzanj earned 100 total points
Comment Utility
Works for me
echo 10.20.30.40 | awk -F. '{print $1"\n"$2"\n"$3"\n"$4}'
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 100 total points
Comment Utility
Did you try this?

awk -F\. '{print $1 "\n" $2 "\n" $3 "\n" $4}
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 76

Assisted Solution

by:arnold
arnold earned 100 total points
Comment Utility
echo QUAD | awk -F\. ' (NF == 4  { print $1"\n"$2"\n"$3"\n"$4"\n" } '

NF is the equal to the number of elements. If there are not the four octets, there will be no output.

. ' " , etc. have to be escaped (\) when those are the delimeter.
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 100 total points
Comment Utility
Do you have to use awk?

If not, easier to do

echo 10.20.30.40|tr '.' '\n'

Open in new window

0
 

Author Closing Comment

by:TIMFOX123
Comment Utility
Everybody did such a great job

ozo has the answer I used.

tintin, your answer just rocks !!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now