Whats the syntax for 'cut' in following?


 
Thread Tools Search this Thread
Operating Systems Solaris Whats the syntax for 'cut' in following?
# 1  
Old 05-26-2009
CPU & Memory Whats the syntax for 'cut' in following?

Guys
I am trying to get all physical plus logical interfaces on a host to pass them to a 'for' loop.

'ifconfig -a' gives me all interfaces like following...i need to cut last ':' from this list.What 'cut' syntax i need to use?

bash-2.05$
ifconfig -a|awk '{print $1}'|sort|uniq|egrep -v "^group|inet|lo0|ether"|awk '{print $1}'
ba0:
ce0:
ce0:1:
ce0:2:
ce1:
qfe0:
# 2  
Old 05-26-2009
You don't need quite so many pipelines:

Code:
ifconfig -a | nawk '$1 ~ /:$/ && $1 !~ /^lo/ {sub(":$", "", $1); print $1}'

# 3  
Old 05-26-2009
Here is something simpler:
Code:
ifconfig -a | sed -n '/flags/ s/:.*$//p'

and that one should ignore the loopback:

Code:
ifconfig -a | sed -n '/BROADCAST/ s/:.*$//p'


Last edited by jlliagre; 05-26-2009 at 10:00 AM.. Reason: I'm picking the loopback with the first solution posted.
# 4  
Old 05-28-2009
CPU & Memory

Code:
ifconfig -a | nawk '$1 ~ /:$/ && $1 !~ /^lo/ {sub(":$", "", $1); print $1}'

thanks ...this worked....

on the same lines i am trying to get this:

hardware address for logical interface... first of all.... does a logical interface have a hardware address?

'arp -a' |grep "<hostname>" displays only the physical interfaces and h/w addresses associated with them...

how can i get h/w address for a logical interface?

any clues/ideas welcome !!
# 5  
Old 05-28-2009
Quote:
Originally Posted by ak835
Code:
ifconfig -a | nawk '$1 ~ /:$/ && $1 !~ /^lo/ {sub(":$", "", $1); print $1}'

thanks ...this worked....
Anything wrong with my simpler (I believe) suggestion:
Code:
 ifconfig -a | sed -n '/BROADCAST/ s/:.*$//p'

Quote:
hardware address for logical interface... first of all.... does a logical interface have a hardware address?
No. It shares the same hardware address as the physical interface it depends on.
# 6  
Old 05-29-2009
MySQL

Code:
ifconfig -a | sed -n '/BROADCAST/ s/:.*$//p'

This does not give me logical interfaces.I am pasting o/p below

Code:
bash-2.05$ ifconfig -a
lo0: flags=<>
        inet <>
ce0: flags=<>
        inet <>
        groupname ipmp
ce0:1: flags=<>
        inet <>
ce1: flags=<>
        inet <>
        groupname ipmp
ce5: flags=<>
        inet 10.10.0.236 netmask fffffc00 broadcast 10.10.3.255

HTML Code:
Other information in above o/p not displayed
Here is what this command does:

Code:
bash-2.05$ ifconfig -a | sed -n '/BROADCAST/ s/:.*$//p'
ce0
ce0
ce1
ce5

Thanks for answering other query.

Regards
Abhi
# 7  
Old 05-29-2009
My mistake, there should have been a space after the colon:
Code:
ifconfig -a | sed -n '/BROADCAST/ s/: .*$//p'

Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using :<<cut / cut to comment out block of bash script

I am using : << cut / cut to comment out block of code. Works fine on few lines of script, then it gives me this cryptic error when I try to comment out about 80 lines. The "warning " is at last line of script. done < results 169 echo "END read all positioning parameters" 170... (8 Replies)
Discussion started by: annacreek
8 Replies

2. UNIX for Beginners Questions & Answers

Cut command: can't make it cut fields

I'm a complete beginner in UNIX (and not a computer science student either), just undergoing a tutoring course. Trying to replicate the instructions on my own I directed output of the ls listing command (lists all files of my home directory ) to My_dir.tsv file (see the screenshot) to make use of... (9 Replies)
Discussion started by: scrutinizerix
9 Replies

3. Shell Programming and Scripting

Function works, trigger causes syntax error, whats my fault??

Needing a hint. Creating that function called Meter my simple script works well. What I want now is to start the last four commented lines to include or trigger a reaction, if there are more than n lines in that .txt-file it shall display that message for example. But the interpreter says there is... (3 Replies)
Discussion started by: 1in10
3 Replies

4. Shell Programming and Scripting

Cut Command error cut: Bad range

Hi Can anyone what I am doing wrong while using cut command. for f in *.log do logfilename=$f Log "Log file Name: $logfilename" logfile1=`basename $logfilename .log` flength=${#logfile1} Log "file length $flength" from_length=$(($flength - 15)) Log "from... (2 Replies)
Discussion started by: dgmm
2 Replies

5. Shell Programming and Scripting

Whats wrong with the syntax

Whats wrong with below logic or syntax???? (4 Replies)
Discussion started by: dsravan
4 Replies
Login or Register to Ask a Question