Concatenating Output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Concatenating Output
# 1  
Old 10-03-2012
Data Concatenating Output

Hello all

The following line :
Code:
df -h | awk '{print $5}'| head -2 |tail -1

gives me an output of '2.2G'

How can I remove the 'G' so that I can use the 2.2 for further calculations ?

Last edited by Franklin52; 10-03-2012 at 08:39 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 10-03-2012
Try like ..
Code:
echo "2.2G"|sed 's/G//g'

# 3  
Old 10-03-2012
Code:
df -h | awk 'NR==2{gsub("G","",$0);print $5}'

NR==2 choose your row you want to print. and column in $..
# 4  
Old 10-03-2012
Code:
df -h | awk 'NR==2{print $5+0;exit}'

This User Gave Thanks to elixir_sinari For This Post:
# 5  
Old 10-03-2012
Thanks.
One more thing. File systems can be in MBs or GBs.... So im not sure what result would I get. It could be 2G or 2M.... So how can I modify your result to make sure that it removes the M or G , which ever appears in the result ?
# 6  
Old 10-03-2012
Have you tried what I've suggested?
# 7  
Old 10-03-2012
Dosent Work. Its Returns 0.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Concatenating strings to "tr" command output

Hi All, Please help me in forming command for the following scenario. My input string (msg)is \'01\',\'02\',\'03\',\'04\',\'05\',\'06\' , i have removed \ and ' using echo $msg|tr -d '\\'|tr -d "'" which gave me output as 01,02,03,04,05,06. I am half done here. Now i want to append... (8 Replies)
Discussion started by: chpsam
8 Replies

2. UNIX for Dummies Questions & Answers

Concatenating columns

Hi I have the following input file, It is a tab delimited file ISOCOUNTRYCODE POSTALCODE CITY HNO STREETBASENAME STREETTYPE FIN 40950 Muurame Teollisuus tie FIN 02160 Westendintie FIN 33210 Tampere Päämäärän kuja... (2 Replies)
Discussion started by: ramky79
2 Replies

3. UNIX for Dummies Questions & Answers

Concatenating

Hi, I have file called "3rdparty.dat" I want to concatenate current YYYYMMDD to it. Snd result should be like 3rdParty20111110.dat. How can i do this? Thanks in advance. (3 Replies)
Discussion started by: raj.shah.0609
3 Replies

4. Shell Programming and Scripting

de concatenating a string

I have a variable var=string1:string2:string3 I want to get the string de-concatenated and put it as var1=string1 var2=string2 var3=string3 Thanks in advance. ---------- Post updated at 02:18 PM ---------- Previous update was at 01:45 PM ---------- I got the solution as below:... (2 Replies)
Discussion started by: Deepak62828r
2 Replies

5. Shell Programming and Scripting

need help in concatenating

Hi All , i`m writing a script , i stucked in middle . Script echo "Please Enter the INSTANCE name" read iName echo "The INSTANCE name is $iName" more /opt/IBMIHS*/conf/httpd.conf_"$iName" script end here i`m getting error as : Error /opt/IBMIHS*/conf/httpd.conf_w101:... (7 Replies)
Discussion started by: radha254
7 Replies

6. Red Hat

Concatenating variables

Hi all, I'm trying to do a very simple script, as you can see as follow: #!/bin/bash #Valorizzazione Token presenti nel file di properties var_path_weblogic="`cat weblogic.properties | grep "dir_wl" | /usr/xpg4/bin/awk '{print $3}'`" var_ip_address="`cat... (5 Replies)
Discussion started by: idro
5 Replies

7. Shell Programming and Scripting

Concatenating Different # of Variables

Hi, I'm quite new at unix and was wondering if anyone could help me with this. I have 2 arrays: eg. STAT=online, STAT=offline, STAT=online WWN=xxxx1, WWN=xxxx2, WWN=xxxx3 I got these information from a script using fcinfo hba-port that runs through a loop. Now, I want to store... (2 Replies)
Discussion started by: jake_won
2 Replies

8. Shell Programming and Scripting

Concatenating Strings

Is there any function to concatenate strings in shell script (2 Replies)
Discussion started by: radhika03
2 Replies

9. UNIX for Dummies Questions & Answers

concatenating x files into a one...

... i have 4 files to concatenate but in a certain order and i wanted to do it in a shorter one line command , if possible ! 4 files : file , file0 , file1 and file2 file1 into file2 file0 into the result file into the result thanks in advance Christian (1 Reply)
Discussion started by: Nicol
1 Replies

10. Shell Programming and Scripting

Concatenating Variables

FILE_DATE=$(date +"%Y%m%d_%H%M")_ FILE_PREFIX=${FILE_DATE} echo $FILE_PREFIX JS_LOG_DIR="E:\DecisionStream Jobs\Invoice Balance Fact Jobs" echo $JS_LOG_DIR --This is where the problem surfaces. The last line of this script does a rsh to an NT machine and one of the parameters is the... (2 Replies)
Discussion started by: photh
2 Replies
Login or Register to Ask a Question