awk extract certain digits from file with index substr


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk extract certain digits from file with index substr
# 1  
Old 12-20-2011
awk extract certain digits from file with index substr

I would like to extract a digit from $0 starting 2,30 to 3,99 or 2.30 to 3.99

Can somebody fix this?

Code:
awk --re-interval  '{if($0 ~ /[2-3]{1}[,.][0-9]{2}/) {print FILENAME, substr($0,index($0,/[2-3]{1}[,.][0-9]{2}/) , 4)}}'

HTML Code:
input
abcdefg sdlfkj 3,29 g. lasdfj
alsdfjasl 2.86 gr. slkjds sldkd
lskdjfsl sdfkj kdjlksj 3,34 g sldkfj
...
# 2  
Old 12-20-2011
Does it have to be AWK? Is Perl acceptable?
# 3  
Old 12-20-2011
Quote:
Originally Posted by bartus11
Does it have to be AWK? Is Perl acceptable?
Don't have perl on my system. Smilie
# 4  
Old 12-20-2011
Code:
nawk '{
  for(i=1;i<=NF;i++)
    if ($i ~ "^[2-3][.,][0-9][0-9]$" && $i>=2.30 && $i<=3.99)
          print $i
}' myFile

This User Gave Thanks to vgersh99 For This Post:
# 5  
Old 12-20-2011
Quote:
Originally Posted by vgersh99
Code:
nawk '{
  for(i=1;i<=NF;i++)
    if ($i ~ "^[2-3][.,][0-9][0-9]$" && $i>=2.30 && $i<=3.99)
          print $i
}' myFile

INDEED! Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

sed / awk script to delete the two digits from first 3 digits

Hi All , I am having an input file as stated below 5728 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r03_q_reg_20_/Q 011 611 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 011 3486... (4 Replies)
Discussion started by: kshitij
4 Replies

2. UNIX for Beginners Questions & Answers

Substr with % - extract numbers only

# cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.5 (Maipo) I have this script that will monitor filesystems and send me e-amil alerts. #! /bin/ksh DIST_LIST=monitor@...com WORKDIR=/home/monitor WARNLEVEL=90 MAIL_SUBJ="filesystems monitor on "$(hostname) ... (3 Replies)
Discussion started by: danielshell
3 Replies

3. Shell Programming and Scripting

Substr/Instr in shell script or extract part of text

Hi, I need to extract part of a text to two variables text is "PL/SQL procedure successfully completed. ERROR ----------------------------------------------------------------- Test Error Message PLUSVAR ---------- 1" I want "Test Error Message" in one variable and "1" in another variable.... (11 Replies)
Discussion started by: vedavrath
11 Replies

4. Shell Programming and Scripting

Relocation strings using awk/sed from a index file

Hi All, I'd always appreciate all helps from this website. I would like to relocate strings based on the index number from an index file. Index numbers are shown on the first column in the index file (index.txt) and I would like to relocate "path" based on index numbers. Paths are placed... (11 Replies)
Discussion started by: jypark22
11 Replies

5. Shell Programming and Scripting

How to use substr to extract character between two semicolon?

Dear folks Hello I have a data set which one of the column of this data set are string and I want to extract numbers which is between two ":". However, I know the substr command which will do this operation but my problem is the numbers between two ":" have different digits. this will make my... (11 Replies)
Discussion started by: sajmar
11 Replies

6. Shell Programming and Scripting

Is it possible to index substr from right to left?

Hello, all Suppose I have a string "0123456789", if i want to get the substr "56", I know I can use following method: $ string="0123456789" $ echo ${string:5:2} 56 I am wondering if there is some command like: $ echo ${string:6:-2} which can also get the same output "56"? (3 Replies)
Discussion started by: littlewenwen
3 Replies

7. Shell Programming and Scripting

How to serach for Values grater tan 4 digits in a file using Awk Command

Dear All iam looking for a help in how to search for values grreater than 4 numbers. I run the below commad but its still not working awk '{ print $2 " " $5 }' AllRecords | grep "+008" | grep "length" > 4 Can any one help me. Regards Kadir (1 Reply)
Discussion started by: samura
1 Replies

8. Filesystems, Disks and Memory

why the inode index of file system starts from 1 unlike array index(0)

why do inode indices starts from 1 unlike array indexes which starts from 0 its a question from "the design of unix operating system" of maurice j bach id be glad if i get to know the answer quickly :) (0 Replies)
Discussion started by: sairamdevotee
0 Replies

9. Shell Programming and Scripting

(awk) compare files in dir with an index file

Using awk I have an index file which has been seperated into 5 fields. The first field contains file names. What I need to do is check to see if a file exists in my current directory that is not in the first field of my index file. If its not i print out a message. Please help! (4 Replies)
Discussion started by: xthexonex
4 Replies

10. Shell Programming and Scripting

Using Awk in shell script to extract an index of a substring from a parent string

Hi All, I am new to this shell scripting world. Struck up with a problem, can anyone of you please pull me out of this. Requirement : Need to get the index of a substring from a parent string Eg : index("Sandy","dy") should return 4 or 3. My Approach : I used Awk function index to... (2 Replies)
Discussion started by: sandeepms17
2 Replies
Login or Register to Ask a Question