The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
remove first column of a space delimited txt ajp7701 Shell Programming and Scripting 1 04-18-2008 05:10 PM
remove space characters melanie_pfefer Shell Programming and Scripting 1 03-11-2008 01:45 PM
Remove unregconized space from a string Ricole UNIX for Dummies Questions & Answers 3 02-29-2008 04:35 AM
Perl code to differentiate numeric and non-numeric input Raynon Shell Programming and Scripting 11 08-04-2007 11:32 AM
remove space in front or end of each field happyv Shell Programming and Scripting 6 03-22-2007 02:05 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-17-2008
ali560045's Avatar
ali560045 ali560045 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 328
to remove space after numeric

I have a script that shows me the disk SPace used by different dir under my home dir:


Code:
#!/bin/ksh
cd /ednpdtu3/u01/pipe

p1=`df -g | tail -1 | tr -s " " | cut -d " " -f2`
echo "Total Disk Space of Home Dir is $p1 GB"
p2=`df -g | tail -1 | tr -s " " | cut -d " " -f3`
echo "Total Disk Space Free in Home Dir is $p2 GB"

count=`ls -ltr | grep ^d | wc -l`
echo "$count Dir found in HOME DIR"

a1=1
while [ $a1 -le $count ]
do
  b=`ls -ltr | grep ^d | head -$a1 | tail -1 | tr -s " " | cut -d " " -f9`
  #echo $b
  a1=`expr $a1 + 1`
  a2=`du -sk $b`
  echo "$a2" 
done

------------------------------------------------------------------------

Output i m getting:
28 ssh

89508 Outgoing

6393868 Incoming

4 Mail

----------------------------------------------------------

But i want to get only numeric value i.e. whenever it encounter space , it should remove spaces and watever is after spaces so that i can get onl;y numeric part. My o/p should be like below

28

89508

6393868

4
--------------------------------------------------------------

I know we can do it by SED and we have to implement this in a2=`du -sk $b` . I tried some commands with sed
,but not successfull

a2=`du -sk $b | `sed 's/ //g'-----> not working

I m pretty much sure we have to implement the logic in that part of the script i.e. a2=`du -sk $b` and using SED but not getting the correct way to use SED

Plz help me in this

Last edited by Franklin52; 09-17-2008 at 06:13 AM.. Reason: adding code tags
  #2 (permalink)  
Old 09-17-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,348

Code:
sed 's/ .*//'

or:


Code:
awk '{print $1}'

Regards
  #3 (permalink)  
Old 09-17-2008
ali560045's Avatar
ali560045 ali560045 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 328
thanks a lot got the answer by command du -sk $b | awk '{print $1}'
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:11 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0