Solved

splitting octets with awk

Posted on 2013-01-25
6
275 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
ID: 38820025
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
ID: 38820033
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
ID: 38820042
Did you try this?

awk -F\. '{print $1 "\n" $2 "\n" $3 "\n" $4}
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 77

Assisted Solution

by:arnold
arnold earned 100 total points
ID: 38820045
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
ID: 38821350
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
ID: 38825223
Everybody did such a great job

ozo has the answer I used.

tintin, your answer just rocks !!
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

815 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

8 Experts available now in Live!

Get 1:1 Help Now