Sponsored Content
Top Forums Shell Programming and Scripting How to search, replace and multiply variable within awk? Post 302910228 by kieranfoley on Wednesday 23rd of July 2014 07:05:42 AM
Old 07-23-2014
How to search, replace and multiply variable within awk?

I have a file that reports the size of disks GB's or TB's - I need the file to report everything in MB's. Here is an extract of the file - the last column is the disk size.


Code:
19BC 2363 20G
1AA3 2363 2.93T
1A94 2363 750G


Whenever I come across a G I want to delete the G and multiply by 1024 and whenever I get "T" I want to delete the T and multiply by 1048576.

So the output file would look like

Code:
19BC 2363 20480
1AA3 2363 3072327
1A94 2363 768000

I had this working to convert the G but then I saw that there were "T"'s in the file and I am struggling to convert G's and T's...Here is what I was using to deal with the G's

Code:
cat file | sed 's/G$//g' | awk '{MB=$3*1024; print$1,$2,MB}'

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

search & replace in variable

Can I use search & replace in any variable? Suppose I have one variable named var1 which holds value "abcabc" I need to search 'a' in var1 and want to replace with 'x' like 'xbcxbc'. Is it possible? Can you provide me an example? Malay (3 Replies)
Discussion started by: malaymaru
3 Replies

2. Shell Programming and Scripting

multiply variable

I need to multiply the value of a variable and then store it in another variable. I have EXPHOURINSEC=$(($EXPDATEHOUR * 3600)) but i get an error saying the * is unexpected. Im using ksh (4 Replies)
Discussion started by: fwabbly
4 Replies

3. Shell Programming and Scripting

Perl search and replace in range using variable

Hi. I have a file with asterisk field separators and backslash line terminators. The first field in each line names the line type. I am trying to process each range separately. Here's what the data looks like: BA*DATA\ LS*DATA1*DATA2*00020*\ TA*DATA1*DATA2*DATA3*\ TA*DATA1*DATA2*DATA3*\... (1 Reply)
Discussion started by: yoi2hot4ya
1 Replies

4. Shell Programming and Scripting

awk - replace number of string length from search and replace for a serialized array

Hello, I really would appreciate some help with a bash script for some string manipulation on an SQL dump: I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump. This is quite easy with sed: sed -e... (1 Reply)
Discussion started by: otrotipo
1 Replies

5. Shell Programming and Scripting

search the pattern in a file and replace with variable already defined previously in csh

I want to replace a certain pattern with the variable already defined. e.g. set path_verilog = /home/priya/bin/verilogfile my file contents are : verilog new verilog is defined here verilog_path_comes I am using the below command sed 's/verilog_path_comes/'$path_verilog'/g' <filename>... (2 Replies)
Discussion started by: nehashine
2 Replies

6. Shell Programming and Scripting

search replace with loop and variable

Hi, could anyone help me with this, tried several times but still not getting it right or having enough grounding to do it outside of javascript: Using awk or sed or bash: need to go through a text file using a for next loop, replacing substrings in the file that consist of a potentially multi... (3 Replies)
Discussion started by: wind
3 Replies

7. Shell Programming and Scripting

Multiply certain column to variable

Hi experts, I want to multiply certain columns to variable, data : 1 2 3 4 5 6 7 8 9 result with var = 2 for column 3,6,9 ... (every columns which can be divided to 3): 1 2 6 4 5 12 7 8 18 I have tried : awk 'BEGIN{FS=OFS=" "}{print $1,$2,$3*a,$4,$5,$6*a,$7,$8,$9*2 }' a=2 file.txt but how... (6 Replies)
Discussion started by: guns
6 Replies

8. UNIX for Dummies Questions & Answers

Search and replace with variable

Hello all, I stumbled upon a command line for multiple search and replace within given destination perl -pi -w -e 's/SEARCH_FOR/REPLACE_WITH/g;' *.html I want to replace the following line where the date is the variable, from <div class="meta"> <ul> <li>05.05.2015 with date tags, like... (5 Replies)
Discussion started by: uninuub
5 Replies

9. Shell Programming and Scripting

awk search and replace nth column by using a variable.

I am passing a variable and replace nth value with the variable. I tried using many options in awk command but unable to ignore the special characters in the output and also unable to pass the actual value. Input : "1","2","3" Output : "1","1000","3" TempVal=`echo 1000` Cat... (2 Replies)
Discussion started by: onesuri
2 Replies

10. Shell Programming and Scripting

awk variable search and line count between variable-search pattern

Input: |Running the Rsync|Sun Oct 16 22:48:01 BST 2016 |End of the Rsync|Sun Oct 16 22:49:54 BST 2016 |Running the Rsync|Sun Oct 16 22:54:01 BST 2016 |End of the Rsync|Sun Oct 16 22:55:45 BST 2016 |Running the Rsync|Sun Oct 16 23:00:02 BST 2016 |End of the Rsync|Sun Oct 16 23:01:44 BST 2016... (4 Replies)
Discussion started by: busyboy
4 Replies
bitesize.d(1m)							   USER COMMANDS						    bitesize.d(1m)

NAME
bitesize.d - analyse disk I/O size by process. Uses DTrace. SYNOPSIS
bitesize.d DESCRIPTION
This produces a report for the size of disk events caused by processes. These are the disk events sent by the block I/O driver. If applications must use the disks, we generally prefer they do so sequentially with large I/O sizes, or larger "bites". Since this uses DTrace, only users with root privileges can run this command. EXAMPLES
Sample until Ctrl-C is hit then print report, # bitesize.d FIELDS
PID process ID CMD command and argument list value size in bytes count number of I/O operations NOTES
The application may be requesting smaller sized operations, which are being rounded up to the nearest sector size or UFS block size. To analyse what the application is requesting, DTraceToolkit programs such as Proc/fddist may help. DOCUMENTATION
See the DTraceToolkit for further documentation under the Docs directory. The DTraceToolkit docs may include full worked examples with ver- bose descriptions explaining the output. EXIT
bitesize.d will sample until Ctrl-C is hit. AUTHOR
Brendan Gregg [Sydney, Australia] SEE ALSO
iosnoop(1M), seeksize(1M), dtrace(1M) version 1.00 Jun 15, 2005 bitesize.d(1m)
All times are GMT -4. The time now is 01:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy