Remove letter from $1 using awk or sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove letter from $1 using awk or sed
# 1  
Old 10-25-2011
Remove letter from $1 using awk or sed

I have a file:
Code:
575G /local/mis/SYBDUMP

I want to remove the G, K, M or T so I can use $1 in awk or sed to do math.
I want to end up with a file containing:
Code:
575 /local/mis/SYBDUMP

It should not matter how small or large the numeric numbers are so if 2, 3, 4, or 5 digits etc I want to see them in my output file.

How can this be done using awk, sed or whatever. Thanks in advance for your help.Smilie

Last edited by radoulov; 10-25-2011 at 03:16 PM.. Reason: Code tags!
# 2  
Old 10-25-2011
Are you trying to rename the file ?? It has whitespace yes ??

Or do you just want the numerical value at the beginning of the file name ??
# 3  
Old 10-25-2011
Quote:
Originally Posted by tamvgi
I have a file:
Code:
575G /local/mis/SYBDUMP

I want to remove the G, K, M or T so I can use $1 in awk or sed to do math.
[...]
You don't need to remove the trailing alphabetic character(s) in order to do the math with awk ...
# 4  
Old 10-25-2011
Code:
echo '575G /local/mis/SYBDUMP' | nawk '$1+=0'

This User Gave Thanks to vgersh99 For This Post:
# 5  
Old 10-25-2011
AlphaLexman,

It can go to the same file name or new one and the file has white spaces and I want both values....

---------- Post updated at 02:31 PM ---------- Previous update was at 02:25 PM ----------

radoulov,

I later compare this file with another that need to have the same format, using AIX/Unix and Linux df -g and df -h to produce compared files later in my script. Will you give an example of math with awk in this type situation?
# 6  
Old 10-25-2011
I thought you needed something like this:

Code:
zsh-4.3.12[t]% cat infile
575G /local/mis/SYBDUMP
333G /local/mis/SYBDUMP
512G /local/mis/SYBDUMP
zsh-4.3.12[t]% awk 'END { print t } { t += $1 }' infile
1420


Or I am missing something?
# 7  
Old 10-25-2011
Code:
echo '575G /local/mis/SYBDUMP' | nawk '{$1+=15;print}'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove repeated letter words

Hi, I have this text file with these words and I need help with removing words with repeated letter from these lines. 1 ama 5 bib 29 bob 2 bub 5 civic 2 dad 10 deed 1 denned 335 did 1 eeee 1 eeeee 2 eke 8... (4 Replies)
Discussion started by: crepe6
4 Replies

2. Shell Programming and Scripting

Want to remove / and character using awk or sed

Below i am trying to remove "/" and "r" from the output, so i need output as: hdiskpower3 hdisk0 hdisk1 #inq | grep 5773 | awk '{print $1}' | sed 's/dev//g' | awk -F"/" '{$1=$1}1' .....................................................//rhdiskpower0 //rhdiskpower1 //rhdiskpower2... (3 Replies)
Discussion started by: aix_admin_007
3 Replies

3. Shell Programming and Scripting

sed awk to remove the , in a string

Dear All, Can anyone help to remove the , bewteen "" in a string by using sed or awk? e.g. input : 1,4,5,"abcdef","we,are,here",4,"help hep" output:1,4,5,"abcdef","wearehere",4,"help hep" Thanks, Mimi (5 Replies)
Discussion started by: mimilaw
5 Replies

4. Shell Programming and Scripting

Awk/sed - add space between dot and letter

I need to change . into . so that e.g. A.Jbecomes A. JI have tried sed 's/\./\.\ /g' but that didn't work. (9 Replies)
Discussion started by: locoroco
9 Replies

5. Shell Programming and Scripting

Remove apostrophe and a letter followed by it

Hi All, For example, I have some words like these: cabinet's school's field's you'll I know how to remove apostrophe from these words using this command: cat filename | tr -s "\'" ' ' But I am not sure how I can remove the letter followed by the apostrophe, so that my output... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

6. Shell Programming and Scripting

How to remove spaces using awk,sed,perl?

Input: 3456 565 656 878 235 8 4 8787 3 7 35 878 Expected output: 3456 565 656 878 235 8 4 8787 3 7 35 878 How can i do this with awk,sed and perl? (10 Replies)
Discussion started by: cola
10 Replies

7. Shell Programming and Scripting

sed/awk remove newline

Hi, I have input file contains sql queries i need to eliminate newlines from it. when i open it vi text editor and runs :%s/'\n/'/g it provides required result. but when i run sed command from shell prompt it doesn't impact outfile is still same as inputfile. shell] sed -e... (6 Replies)
Discussion started by: mirfan
6 Replies

8. Shell Programming and Scripting

How to remove lines before and after with awk / sed ?

Hi guys, I need to remove the pattern (ID=180), one line before and four lines after. Thanks. (5 Replies)
Discussion started by: ashimada
5 Replies

9. Shell Programming and Scripting

a SED/AWK way to remove everything except...

Hi all, I have a logfile which has lines as following: DOMAIN\username,Deposit,DOMAIN\ServiceAccountName,25/03/2010,00:10,\\SERVER,,,,/Ts=4BAA9BD6,,,10.00,10.03 It's a log of a pcounter print charge system. I need to only have the first part (domain\username) and the second last... (4 Replies)
Discussion started by: necron
4 Replies

10. Shell Programming and Scripting

Sed or Awk to remove specific lines

I have searched the forum for this - forgive me if I missed a previous post. I have the following file: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah alter table "informix".esc_acct add constraint (foreign key (fi_id) references "informix".fi ... (5 Replies)
Discussion started by: Shoeless_Mike
5 Replies
Login or Register to Ask a Question