Extract data between two characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract data between two characters
# 1  
Old 02-18-2010
Bug Extract data between two characters

Hi,

how can i extract a data between two characters



input file is



Code:
abc  efg hig  - 99.4% (16337276 kB) used
efg klm - 47.1% (7734968 kB) used 
hij - 99.4% (16341464 kB) used
klm -93.7% (15394516 kB) used


output should be


Code:
99.4
47.1
99.4
93.7


thanks in advance

Last edited by zxmaus; 02-18-2010 at 04:40 AM.. Reason: added code tags
# 2  
Old 02-18-2010
Try This.

Input file name - test.txt
script name - extract.pl

perl extract.pl test.txt

Code:
#!/usr/bin/perl

while (<>) {
if (/\-\s(.+?)\%/) { print $1,"\n"; }
}

# 3  
Old 02-18-2010
Code:
sed 's/.*-[ ]*\([0-9.]*\)%.*/\1/g' input.txt

# 4  
Old 02-18-2010
Thanks pravin it worked , is there any way to do this by using bash instead of perl

---------- Post updated at 02:14 AM ---------- Previous update was at 02:11 AM ----------

Thanks sed command worked for me ..
# 5  
Old 02-19-2010
Try this
Code:
grep  "[0-9]*\.[0-9]%" -o  <filename>

Put this line in to a bash script
# 6  
Old 02-19-2010
Code:
sed 's/.*- *//;s/%.*//' infile

Code:
awk -F "[-%] *" '{print $2}' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract characters from a string name

Hi All, I am trying to extract only characters from a string value eg: abcdedg1234.cnf How can I extract only characters abcdedg and assign to a variable. Please help. Thanks (2 Replies)
Discussion started by: abhi_123
2 Replies

2. Shell Programming and Scripting

Extract 4 digit characters

* hdisk99 U5791.001.9920BZ4-P1-C05-T1-W500507630E060C14-L401140BA00000000 IBM MPIO FC 1750 * hdisk100 U5791.001.9920BZ4-P1-C05-T1-W500507630E060C14-L401140BB00000000 IBM MPIO FC 1750 * hdisk185 U5791.001.9920BZ4-P1-C05-T1-W500507630E060C14-L401140A000000000 IBM MPIO FC... (2 Replies)
Discussion started by: Daniel Gate
2 Replies

3. Shell Programming and Scripting

extract last 8 characters from a file name

Dear gurus I have several files with the following format filenameCCYYMMDD , that is the last 8 characters will be the date in CCYYMMDD format. eg FILENAME20110523 . Could anyone please put me through on how to extract only the last 8 characters from the files. I am thinking of using awk,sed... (2 Replies)
Discussion started by: erinlomo
2 Replies

4. Shell Programming and Scripting

Extract specific data content from a long list of data

My input: Data name: ABC001 Data length: 1000 Detail info Data Direction Start_time End_time Length 1 forward 10 100 90 1 forward 15 200 185 2 reverse 50 500 450 Data name: XFG110 Data length: 100 Detail info Data Direction Start_time End_time Length 1 forward 50 100 50 ... (11 Replies)
Discussion started by: patrick87
11 Replies

5. Shell Programming and Scripting

Extract data based on match against one column data from a long list data

My input file: data_5 Ali 422 2.00E-45 102/253 140/253 24 data_3 Abu 202 60.00E-45 12/23 140/23 28 data_1 Ahmad 256 7.00E-45 120/235 140/235 22 data_4 Aman 365 8.00E-45 15/65 140/65 20 data_10 Jones 869 9.00E-45 65/253 140/253 18... (12 Replies)
Discussion started by: patrick87
12 Replies

6. Shell Programming and Scripting

extract data from a data matrix with filter criteria

Here is what old matrix look like, IDs X1 X2 Y1 Y2 10914061 -0.364613333 -0.362922333 0.001691 -0.450094667 10855062 0.845956333 0.860396667 0.014440333 1.483899333... (7 Replies)
Discussion started by: ssshen
7 Replies

7. Shell Programming and Scripting

Extract string between two different characters

I want to extract a string from a line in a text file between two different characters: for example: :string" I want to extract string. It has to be done in a one-liner. (11 Replies)
Discussion started by: rein
11 Replies

8. Shell Programming and Scripting

SED to extract characters

Hi, Please let me know how do we write a piece of code to extract characters from a line using SED. (1 Reply)
Discussion started by: Shilpi
1 Replies

9. Shell Programming and Scripting

SED to extract characters

Hi, Please let me know how do we write a piece of code to extract characters from a line using SED. (2 Replies)
Discussion started by: Shilpi
2 Replies

10. UNIX for Dummies Questions & Answers

Grep and extract the characters after

Hi All, I have lines like below in a file A /u/ab/test1.dat A/u/ab/test2.dat A /u/bb/test3.dat A/u/cc/test4.dat I will need /u/ab/test1.dat /u/ab/test2.dat /u/bb/test3.dat /u/cc/test4.dat Pls help Thanks (6 Replies)
Discussion started by: thumsup9
6 Replies
Login or Register to Ask a Question