Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Print header and some lines

Shell Programming and Scripting


Tags
awk

Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 02-14-2013
netdbaind netdbaind is offline
Registered User
 
Join Date: Aug 2012
Last Activity: 27 March 2015, 12:10 PM EDT
Posts: 63
Thanks: 10
Thanked 0 Times in 0 Posts
Wrench Print header and some lines

HI ,

i have to print the first header of df -h (Filesystem Size Used Avail Use% Mounted on)and line which conatin size Network path only.


Code:
Filesystem            Size  Used Avail Use% Mounted on
/test/sda3              35G  1.8G   32G   6% /
/test/sda10            7.8G  1.1G  6.3G  15% /usr
/test/sda12            3.9G   73M  3.7G   2% /usr/local
/test/sda9             7.8G  329M  7.1G   5% /var
/test/sda8             7.8G  3.6G  3.9G  49% /opt
/test/sda7              16G  1.4G   14G  10% /tmp
                      4.0T  523G  3.5T  13% /Network/Test

Sponsored Links
    #2  
Old Unix and Linux 02-14-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 28 July 2015, 6:01 AM EDT
Location: Aachen, Germany
Posts: 6,385
Thanks: 112
Thanked 1,761 Times in 1,647 Posts

Code:
$ sed -n '1p; /Network/p' file
Filesystem            Size  Used Avail Use% Mounted on
                      4.0T  523G  3.5T  13% /Network/Test
$ awk 'NR==1 || /Network/' file
Filesystem            Size  Used Avail Use% Mounted on
                      4.0T  523G  3.5T  13% /Network/Test

The Following User Says Thank You to RudiC For This Useful Post:
netdbaind (02-15-2013)
Sponsored Links
    #3  
Old Unix and Linux 02-14-2013
MadeInGermany MadeInGermany is offline Forum Advisor  
Registered User
 
Join Date: May 2012
Last Activity: 28 July 2015, 6:56 AM EDT
Location: Simplicity
Posts: 2,529
Thanks: 188
Thanked 765 Times in 693 Posts
As described in man df , you can have the desired item (device path or mount path) as extra argument:

Code:
df -h /Network/Test

    #4  
Old Unix and Linux 02-14-2013
Vikram_Tanwar12 Vikram_Tanwar12 is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 21 November 2013, 3:32 AM EST
Posts: 168
Thanks: 13
Thanked 10 Times in 10 Posts
You can also try this.


Code:
df -h | grep -w 'Filesystem\|Network'

Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk print header as text from separate file with getline sdf Shell Programming and Scripting 4 12-14-2011 05:24 PM
Need awk help to print specific columns with as string in a header arv_cds Shell Programming and Scripting 21 05-27-2011 11:31 AM
print lines AFTER lines cointaining a regexp (or print every first and fourth line) kmkocot Shell Programming and Scripting 1 07-06-2010 09:57 PM
print lines except the header madfox Shell Programming and Scripting 2 01-21-2010 08:41 AM
Strip 3 header lines and 4 trailer lines ganesh123 Shell Programming and Scripting 9 03-10-2007 04:15 PM



All times are GMT -4. The time now is 09:19 AM.