SED help delete characters in a string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SED help delete characters in a string
# 1  
Old 08-31-2011
SED help delete characters in a string

Hi Please help me to refine my syntax. I want to delete the excess characters from the out put below.
Code:
-bash-3.00$ top -b -n2 -d 00.20 |grep Cpu|tail -1 | awk -F ":" '{ print $2 }' | cut -d, -f1
  4.4% us

now i want to delete the % and us. How wil i do that to make it just 4.4.

Thanks

Last edited by Franklin52; 08-31-2011 at 10:50 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 08-31-2011
can you just post the output -- or just the output of

Code:
 
top -b -n2 -d 00.20 |grep Cpu

# 3  
Old 08-31-2011
I'm getting the output of 4.4% us.

I need to remove the % us to make it just 4.4 for the output.

What will i add from this syntax to delete the % and us
Code:
top -b -n2 -d 00.20 |grep Cpu|tail -1 | awk -F ":" '{ print $2 }' | cut -d, -f1

the syntax above outputs 4.4% us

Thanks

Last edited by Franklin52; 08-31-2011 at 10:50 AM.. Reason: Please use code tags for code and data samples, thank you
# 4  
Old 08-31-2011
i understand your question. there is unnecessary of grep,tail,cut command

you can easily do all these things in awk itself, thats why i am asking the output
# 5  
Old 08-31-2011
I see. But can you help me itkamaraj?

thanks
# 6  
Old 08-31-2011
Code:
 
$ nawk -F"[:%]" '/Cpu/ {print $2}' test
0.0
$ cat test
top - 16:56:36 up 246 days, 11:14,  3 users,  load average: 0.00, 0.00, 0.00
Tasks: 168 total,   1 running, 167 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   8306856k total,  7940744k used,   366112k free,   285136k buffers

so, in your case, it should be

Code:
 
top -b -n2 -d 00.20 | nawk -F"[:%]" '/Cpu/ {print $2}'

# 7  
Old 08-31-2011
Thank you very much itkamaraj!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Outputting characters after a given string and reporting the characters in the row below --sed

I have this fastq file: @M04961:22:000000000-B5VGJ:1:1101:9280:7106 1:N:0:86 GGGGGGGGGGGGCATGAAAACATACAAACCGTCTTTCCAGAAATTGTTCCAAGTATCGGCAACAGCTTTATCAATACCATGAAAAATATCAACCACACCA +test-1 GGGGGGGGGGGGGGGGGCCGGGGGFF,EDFFGEDFG,@DGGCGGEGGG7DCGGGF68CGFFFGGGG@CGDGFFDFEFEFF:30CGAFFDFEFF8CAF;;8... (10 Replies)
Discussion started by: Xterra
10 Replies

2. Shell Programming and Scripting

sed replace nth characters with string

Hi, I hope you can help me out please? I need to replace from character 8-16 with AAAAAAAA and the rest should stay the same after character 16 gtwrhtrd11111111rjytwyejtyjejetjyetgeaEHT wrehrhw22222222hytekutkyukrylryilruilrGEQTH hrwjyety33333333gtrhwrjrgkreglqeriugn;RUGNEURGU ... (4 Replies)
Discussion started by: stinkefisch
4 Replies

3. Shell Programming and Scripting

How delete characters of specific line with sed?

Hi, I have a text file with some lines like this: /MEDIA/DISK1/23568742.MOV /MEDIA/DISK1/87456321.AVI /MEDIA/DISK2/PART1/45753131.AVI /IMPORT/44452.WAV ... I want to remove the last 12 characters in each line that it ends "AVI". Should look like this: /MEDIA/DISK1/23568742.MOV... (12 Replies)
Discussion started by: inaki
12 Replies

4. Shell Programming and Scripting

Help with sed command - find a string between two characters

Hi, I have a xml file (Config.xml) <Header name="" TDate="" PDate=""> <Config> {"config" { "Nation" "Pri:|Sec:"}} </Config> </Header> Now I wanted to printed all the strings between "". I tried the following cat Config.xml | sed -n 's/.*\.*//p' ... (8 Replies)
Discussion started by: vivek_damodaran
8 Replies

5. Shell Programming and Scripting

sed cut characters of string

helloo I wonder if there's a way to cut characters out of a string and keep only the last 2 by using sed. For example if there's the todays' date: 2012-05-06 and we only want to keep the last 2 characters which are the day. Is there a quick way to do it with sed? (2 Replies)
Discussion started by: vlm
2 Replies

6. Shell Programming and Scripting

sed delete wildcard within a string

Hi I would like to batch delete the "note" entry from bib files. The start would be defined by "note ={" and the end by "}." (see example bib entry below). I tried the following command which does not have any effect: cat input.bib| sed -e 's/note = {.*}.//' > output.bib Any help would... (2 Replies)
Discussion started by: gerggeismann
2 Replies

7. Shell Programming and Scripting

sed delete pattern with special characters

Hi all, I have the following lines <b>A gtwrhwrthwr text hghthwrhtwrtw </b><font color='#06C'>; text text (text) <b>B gtwrhwrthwr text hghthwrhtwrtw </b><font color='#06C'>; text text (text) <b>J gtwrhwrthwr text hghthwrhtwrtw </b><font color='#06C'>; text text (text) and I would like to... (5 Replies)
Discussion started by: stinkefisch
5 Replies

8. Shell Programming and Scripting

Using sed to delete string between delimiters

Hi There! I have the following string which i need to convert to i.e. between each occurence of the delimiter ('|' in this case), i need to delete all characters from the '|' to the ':' so that |10,9:12/xxx| becomes |12/xxx| How can i do this using sed? Thanks in advance! (13 Replies)
Discussion started by: orno
13 Replies

9. Shell Programming and Scripting

Replace string and delete extra characters

Hopefully someone can help out here. This is probably fairly basic, but I've searched and tried several variations of the solutions presented in these forums, so I'll go ahead and ask. How can I locate a string in a file, delete the characters after the string and then replace the string with a... (2 Replies)
Discussion started by: slaubhan
2 Replies

10. UNIX for Dummies Questions & Answers

Using sed to delete a string?

Hi all! Here is my problem : I have a string like the following : 20030613170404;BAN_CAV ; starting script Loader.sh on ; 13/06/2003 at ; 17;04;03 I want to eraze all characters located after "Loader.sh", because there are unuseful. I tried to use sed...but it didnt work....i guess i... (1 Reply)
Discussion started by: HowardIsHigh
1 Replies
Login or Register to Ask a Question