print all configured nics in one line with awk?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting print all configured nics in one line with awk?
# 1  
Old 05-16-2011
Error print all configured nics in one line with awk?

Hi all:
I need to print all configured nics in one line with "|" separating them.
So I use netstat -i since it don't mess with subinterfaces (work like I want)
so with + cut + tail I get rid of the superfluous data
Code:
netstat -i |cut -f 1 -d" " |tail +3

this gaves me
Code:
e1000g1
e1000g2

Then I pipe that with awk using RS=""; FS="\n" because in this way I can deal with the extra blank line that netstat -i reports.
Code:
netstat -i |cut -f 1 -d" " |tail +3 |awk 'BEGIN { RS="" ; FS ="\n" ; OFS="|"} { print $1,$2 }'

My problem is that I want to print all nics in just one line; separated by pipes; hopefully in a for/while loop.
The output that I need:
Code:
e1000g1|e1000g2


Any suggestion to accomplish this?

Thanks a lot!
PD:
1) Using solaris 10 awk.
2) the command must works on global and non-global zones (containers) shared-ip

Last edited by Franklin52; 05-17-2011 at 03:39 AM.. Reason: Please use code tags
# 2  
Old 05-16-2011
Code:
netstat -i | awk -vORS="|" 'NR>2{print $1}'

It produces unnecessary pipe at the end of the output string, but I think you will be able to fix that. If not let me know Smilie
This User Gave Thanks to bartus11 For This Post:
# 3  
Old 05-17-2011
Hi bartus11:

Your code don't work with solaris awk (but it does with gawk)... I'm restricted to use solaris10 awk or nawk.. But give me and idea...

---------- Post updated at 10:07 PM ---------- Previous update was at 04:29 PM ----------

Hi all:
Since I stuck with the printing when there is just one nic and the extra pipe "|" character with this sentence:
Code:
netstat -i |cut -f1 -d" "| egrep -i -v "Name|lo|^$" | nawk -v ORS="|" 'NR>2{print $1}'

I decide to change nawk for paste in this way: ( the nawk version will be my homework)
Code:
netstat -i |cut -f1 -d" " | egrep -i -v "Name|lo|^$"  |paste -s -d"|" -

gaves me the correct number of nics with the | where must be placed and wet rid of the xtra blank line that netstat -i prints.

So I will use the last one until solve the issue with the nawk... thanks a lot to bartus11 (pal u shed me light!! :-)).

Last edited by Franklin52; 05-17-2011 at 03:40 AM.. Reason: Please use code tags
# 4  
Old 05-17-2011
In solaris 10 use the following:
Code:
 
 
dladm show-dev |grep -v unknown |awk '{print $1}'|paste -s -d"|" -

# 5  
Old 05-17-2011
Quote:
Originally Posted by rbadillarx
Hi bartus11:

Your code don't work with solaris awk (but it does with gawk)... I'm restricted to use solaris10 awk or nawk.. But give me and idea...

---------- Post updated at 10:07 PM ---------- Previous update was at 04:29 PM ----------

Hi all:
Since I stuck with the printing when there is just one nic and the extra pipe "|" character with this sentence:
netstat -i |cut -f1 -d" "| egrep -i -v "Name|lo|^$" | nawk -v ORS="|" 'NR>2{print $1}'

I decide to change nawk for paste in this way: ( the nawk version will be my homework)
netstat -i |cut -f1 -d" " | egrep -i -v "Name|lo|^$" |paste -s -d"|" -

gaves me the correct number of nics with the | where must be placed and wet rid of the xtra blank line that netstat -i prints.

So I will use the last one until solve the issue with the nawk... thanks a lot to bartus11 (pal u shed me light!! :-)).
On Solaris try:
Code:
netstat -i | awk 'NR>2{print $1}' ORS="|"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to print the line that matches and the next if line is wrapped

I have a file and when I match the word "initiators" in the first column I need to be able to print the rest of the columns in that row. This is fine for the most part but on occasion the "initiators" line gets wrapped to the next line. Here is a sample of the file. caw-enabled ... (3 Replies)
Discussion started by: kieranfoley
3 Replies

2. Shell Programming and Scripting

awk print everything in new line

Hi, I have the following file and I would like to print everything to new line and the field seperator should be the dash (-). /usr/java/jdk1.6.0_30/bin/java -Dprogram.name=run.sh -server -XX:PermSize=512m -XX:MaxPermSize=512m -XX:NewSize=1g -XX:MaxNewSize=1g -Xmx3g -Xms3g... (3 Replies)
Discussion started by: kmaq7621
3 Replies

3. Shell Programming and Scripting

awk script -print line when $2 > $2 of previous line

Hi all, From a while loop I am reading a sorted file where I want to print only the lines that have $1 match and $2 only when the difference from $2 from the previous line is > 30. Input would be like ... AN237 010 193019 0502 1 CSU Amoxycillin AN237 080 ... (2 Replies)
Discussion started by: gafoleyo73
2 Replies

4. HP-UX

[Solved] a way to tell printer used by configured print queue?

Hello; As the title says, am trying to find our which driver is used for the alraedy working print queues.. neither hpnpf nor hppi seems to give that info .. Any ideas ?? Thnx (2 Replies)
Discussion started by: delphys
2 Replies

5. UNIX for Dummies Questions & Answers

awk...print first line...

hello all, I am trying to use the AWK cmd on unix and trying to figre out how i can only print the first line and now rest of the line...so for example... $ lsnrctl version|grep Version| awk '{print $5}'| awk -F. '{print $1}'|uniq 11 NT Adapter for but i only want 11 to print out there... (3 Replies)
Discussion started by: abdul.irfan2
3 Replies

6. Shell Programming and Scripting

awk to print on the same line

Hi all, I've a script that uses awk to parse the output of wget during a database update. The code I use is: wget -c ftp://ftpsite/file 2>&1 | awk '/0%/ {print}'But this spits out each progress line on a new line: 37250K .......... .......... .......... .......... .......... 80% 10.9M 1s ... (2 Replies)
Discussion started by: euval
2 Replies

7. Shell Programming and Scripting

awk, Why does it print the same line twice?

awk '{print ; print '""'}' in.txt >inf.txt (2 Replies)
Discussion started by: cola
2 Replies

8. Shell Programming and Scripting

awk print the next line on the current line

Ok I have a file with hundreds of lines, four columns, space delimited, TESTB.TXT for example TESTB.TXT --- AA ZZ 12 34 BB YY 56 78 CC XX 91 23 DD VV 45 67 --- I want a new file that has 7 columns, the first four are identical, and the next 3 are the last three of the next line...so... (5 Replies)
Discussion started by: ajp7701
5 Replies

9. Shell Programming and Scripting

AWK print all in one line

Hello, I want to parse a vcal file with awk, and later import the specific output file into excel. I want everything on one line. -------- file testcal.ics ------------- BEGIN:VCALENDAR PRODID:-//WebCalendar-v1.0.5 VERSION:2.0 METHOD:PUBLISH BEGIN:VEVENT... (3 Replies)
Discussion started by: sdohn
3 Replies

10. Shell Programming and Scripting

print any required line by its line no using awk and its NR variable

how to print any required line by its line no using awk and its NR variable for eg: ------------ 121343 adfdafd 21213sds dafadfe432 adf.adf%adf --------------- requied o/p if give num=3 it print: 21213sds -------------------------------------- (2 Replies)
Discussion started by: RahulJoshi
2 Replies
Login or Register to Ask a Question