Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Print header and some lines

Shell Programming and Scripting


Tags
awk

Closed    
 
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: 1 August 2016, 2:53 AM EDT
Posts: 68
Thanks: 11
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 online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 9 December 2016, 6:30 AM EST
Location: Aachen, Germany
Posts: 9,946
Thanks: 201
Thanked 2,960 Times in 2,760 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: 9 December 2016, 4:42 AM EST
Location: Simplicity
Posts: 3,318
Thanks: 254
Thanked 1,077 Times in 976 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

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 06: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 12:31 PM
print lines AFTER lines cointaining a regexp (or print every first and fourth line) kmkocot Shell Programming and Scripting 1 07-06-2010 10:57 PM
print lines except the header madfox Shell Programming and Scripting 2 01-21-2010 09:41 AM
Strip 3 header lines and 4 trailer lines ganesh123 Shell Programming and Scripting 9 03-10-2007 05:15 PM



All times are GMT -4. The time now is 07:33 AM.