|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Cutting Part of Output
Hello all
I'm using bourne shell and need to figure out how to cut out a specific portion of some output. For example, my output from my command is: 12.12.52.125.in-addr.arpa name = hostname.domain.main.gov I need to get just the "hostname.domain.main.gov" part. What I'm trying to do is make files named the "domain" part and putting the hostnames within them. I'm having a bit of trouble cutting out the "hostname" and "domain" part specifically though... Any suggestions? Thanks in advance, folks |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
man cut
|
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
So if I used -d".", how could I get, say the 5th or 6th part?
|
|
#4
|
||||
|
||||
|
Code:
echo "12.12.52.125.in-addr.arpa name = hostname.domain.main.gov" | awk -F"="
'{print $2}' |
| The Following User Says Thank You to palsevlohit_123 For This Useful Post: | ||
lee.n.doan (11-17-2010) | ||
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
Code:
echo "12.12.52.125.in-addr.arpa name = hostname.domain.main.gov" | nawk -F'[ =.]' '{close(out);out=$(NF-2);print $(NF-3)>>out}' |
| The Following User Says Thank You to vgersh99 For This Useful Post: | ||
lee.n.doan (11-17-2010) | ||
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Was confused at the nawk for a sec then realized I should be using gawk
![]() Thanks for all your help guys. I really want to understand why these work though, so could someone explain the '{close(out);out=$(NF-2);print $(NF-3)>>out}' part if its not too much of a hassle? So gawk -F is using "=" as a delimiter and then splitting up the output that way? then I assume the parts are assigned to $# variables then the $(NF-2 or 3) is getting the 'hostname' and 'domain' parts? |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Code:
cut -d '.' -f 6 |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| need a part of output data as output | nitinrp1 | Shell Programming and Scripting | 8 | 03-30-2010 01:33 PM |
| How to capture only some part of output when command executed?? | vijaysachin | Solaris | 4 | 11-17-2009 06:08 AM |
| Redirecting part of output to stdout | Legend986 | Shell Programming and Scripting | 2 | 10-17-2008 03:20 PM |
| Set specific part in command output into variable | orit | Shell Programming and Scripting | 7 | 08-16-2008 10:34 AM |
| cutting part of string | dhaval_khamar | Shell Programming and Scripting | 3 | 07-25-2005 10:18 AM |
|
|