Help with AWK -- quick question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with AWK -- quick question
# 1  
Old 07-18-2007
Help with AWK -- quick question

Ok. I'm just starting to use AWK and I have a question. Here's what I'm trying to do:

uname -n returns the following on my box:

ftsdt-svsi20.si.sandbox.com

I want to pipe this to an AWK statement and make it only print:

svsi20

I tried:

uname -n | awk '{ FS = "." ; print $1 }'

But that prints:

ftsdt-svsi20

How do I get it to exclude everything before the "-" and everything after the "."?
# 2  
Old 07-18-2007
Try

uname -n | awk -F "[.-]" '{ print $1 }'
# 3  
Old 07-18-2007
How about using this...

uname -n | awk '{ FS = "." ; print $1 }' | cut -d '-' -f2

or

uname -n | cut -d '.' -f1| cut -d '-' -f2

the above will give you the o/p svsi20
Hope your objective will be met!

-ilan
# 4  
Old 07-18-2007
Quote:
Originally Posted by qaid786
Try

uname -n | awk -F "[.-]" '{ print $1 }'
That gave me:

awk: syntax error near line 1
awk: bailing out near line 1
# 5  
Old 07-18-2007
as always..... if on Solaris - use 'nawk' instead.
# 6  
Old 07-18-2007
Quote:
Originally Posted by ilan
How about using this...

uname -n | awk '{ FS = "." ; print $1 }' | cut -d '-' -f2

or

uname -n | cut -d '.' -f1| cut -d '-' -f2

the above will give you the o/p svsi20
Hope your objective will be met!

-ilan
wow - the cut command. Why didn't I think of that,..works like a charm. Thanks a bunch.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Quick awk question

gawk 'BEGIN{count=0} /^Jan 5 04:33/,0 && /fail/ && /09x83377/ { count++ } END { print count }' /var/log/syslog what is wrong with this code? i want to search the strings "fail" and "09x83377" from all entries. im grabbing all entries in the log starting from Jan 5 04:33 to the end of the... (3 Replies)
Discussion started by: SkySmart
3 Replies

2. Shell Programming and Scripting

awk :quick question removing empty line.

How to write in awk to remove lines starting with "#" and then process the file: This is not working: cat file|awk '{if ($0 ~ /^#/) $0="";print NF>0}' When I just give cat file|awk '{if ($0 ~ /^#/) $0="";print }' it prints the blank lines . I don't wnat the blank lines along with the... (15 Replies)
Discussion started by: rveri
15 Replies

3. Shell Programming and Scripting

awk Help: quick and easy question may be: How to use &&

Hi Guru's. I am trying to use to check if $5 is greater than 80 & if not 100, then to print $0 : awk '{ if ($5>80) && if ($5 != 100) print $0} But getting error: >bdf1|sed 's/%//g'|awk '{ if ($5>80) && if ($5 != 100) print $0}' syntax error The source line is 1. The error... (6 Replies)
Discussion started by: rveri
6 Replies

4. Shell Programming and Scripting

Quick sed/awk question

Hi fellow linux-ers, I have a quick question for you. I have the following text, which I would like to modify: 10 121E(121) 16 Jan 34S 132E 24 Feb 42 176E(176) 18 Sep 21S 164E 25 May 15 171W(-171) 09 Jul How can I do the following 2 modifications using sed and/or awk? 1. in 1st column,... (1 Reply)
Discussion started by: lucshi09
1 Replies

5. Shell Programming and Scripting

Quick question

When I have a file like this: 0084AF aj-123-a NAME Ajay NAME Kumar Engineer 015ED6 ck-345-c 020B25 ef-456-e 027458 pq-890-p NAME Peter NAME Salob Doctor 0318F0 xy-123-x NAME Xavier Arul NAME Yesu Supervisor 0344CA de-456-d where - The first NAME is followed by... (6 Replies)
Discussion started by: ajay41aj
6 Replies

6. Shell Programming and Scripting

quick question

I am using sed to find a pattern in a line and then I want to retain the pattern + the rest of the line. How is this possible? ie: line is: 14158 05-15-08 20:00 123-1234-A21/deliverable/dhm.a search for 123-1234-A21 ie: echo $line | sed 's/.*\(\{3\}-\{4\}-\{3\}\{5\}\).*/\1/' ... (1 Reply)
Discussion started by: phreezr
1 Replies

7. UNIX for Dummies Questions & Answers

Quick question

Hi, Is there a simple way, using ksh, to find the byte position in a file that a stated character appears? Many thanks Helen (2 Replies)
Discussion started by: Bab00shka
2 Replies

8. UNIX for Dummies Questions & Answers

Quick Question

Hi, I am new to UNIX, and am learning from this tutorial : http://www.ee.surrey.ac.uk/Teaching/Unix/index.html It keeps telling me to files downloaded from the internet (like .txt files) to the directory, and I dont know how to. How do I add .txt files to my directory? Thanks. (6 Replies)
Discussion started by: IAMTHEEVILBEAN
6 Replies

9. UNIX for Dummies Questions & Answers

Quick Question

Hello There! I am trying to write this SIMPLE script in Bourne Shell but I keep on getting syntax errors. Can you see what I am doing wrong? I've done this before but I don't see the difference. I am simply trying to take the day of the week from our system and when the teachers sign on I want... (7 Replies)
Discussion started by: catbad
7 Replies

10. UNIX for Dummies Questions & Answers

A Quick Question

Wat is the difference between the cp mv ln etc in /usr/sbin/static and cp mv ln functions in /usr/bin (4 Replies)
Discussion started by: DPAI
4 Replies
Login or Register to Ask a Question