Awk substring falls between two values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk substring falls between two values
# 1  
Old 06-10-2008
Awk substring falls between two values

Hi guys, hopefully you can give me a hand with this before my monitor has a nasty accident! Smilie

I have the following line in a script:

awk 'int(substr($1,2,2))>'06' && int(substr($1,2,2))<'08' ' ANYOLDFILE.log

... which when ran against this data file:

[07:50:37,459] [Some stuff] [Some more stuff]
[08:13:37,459] [Some stuff] [Some more stuff]


... correctly returns:

[07:50:37,459] [Some stuff] [Some more stuff]

But I can't work out for the life of me the syntax to use a variable string instead of the values '06' and '08'. I've tried every combination I can think of but none of them work. I don't get an error, but it doesn't return any data.

Anyone know what the answer is?

Also I have been forced to ask for results between 6 and 8 because I couldn't manage to get it to do a simple check for =7, so if you know how to do that as well, you'll get a double dose of karma for the day!

Thanks in advance. Smilie
# 2  
Old 06-10-2008
First of all, what's wrong with:

Code:
v=7
grep "^\[0*$v" infile

In Awk it would be:
(use nawk or /usr/xpg4/bin/awk on Solaris)

Code:
awk '$0 ~ p' p="^[[]0*7" infile

# 3  
Old 06-10-2008
Absolutey nothing wrong with that it works like a charm thanks. Does the ^ on both examples indicate a start of line?
# 4  
Old 06-10-2008
Yes.

(message too short)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk file to read values from Db2 table replacing hard coded values

Hi, I want to replace a chain of if-else statement in an old AWK file with values from Db2 table or CSV file. The part of code is below... if (start_new_rec=="true"){ exclude_user="false"; user=toupper($6); match(user, "XXXXX."); if (RSTART ==2 ) { ... (9 Replies)
Discussion started by: asandy1234
9 Replies

2. Shell Programming and Scripting

Filter uniq field values (non-substring)

Hello, I want to filter column based on string value. All substring matches are filtered out and only unique master strings are picked up. infile: 1 abcd 2 abc 3 abcd 4 cdef 5 efgh 6 efgh 7 efx 8 fgh Outfile: 1 abcd 4 cdef 5 efgh 7 efxI have tried awk '!a++; match(a, $2)>0'... (32 Replies)
Discussion started by: yifangt
32 Replies

3. Shell Programming and Scripting

Value falls between two values from different files

Hi, I have two files cat 1 100 1 110 2 113 4 230 5 334 7 500 8 900 10 I have another file cat 2 100 200 201 300 301 400 401 500 501 600 601 700 (3 Replies)
Discussion started by: jacobs.smith
3 Replies

4. UNIX for Advanced & Expert Users

awk if/substring/append help

Hi All, I need some help with an awk command: What I'm trying to do is append "MYGROUP: " to text with the substring "AT_" the input file follows this format: AT_xxxxxx Name1 Name2 AT_xxxxxx NameA NameB I want the output to be: MYGROUP: AT_xxxxx Name1 Name2 MYGROUP:... (2 Replies)
Discussion started by: bikecraft
2 Replies

5. Shell Programming and Scripting

AWK: Substring search

Hi I have a table like this I want to know how many times the string in 2nd column appears in the first column as substring. For example the first string of 2nd column "cgt" occurs 3 times in the 1st column and "acg" one time. So my desired output is THank you very much in advance:) (14 Replies)
Discussion started by: polsum
14 Replies

6. Shell Programming and Scripting

Getting substring with awk

Hi Team, How to get the last 3 characters of a String irrespective of their length using awk? Thanks Kinny (5 Replies)
Discussion started by: kinny
5 Replies

7. Shell Programming and Scripting

Substring using sed or awk

I am trying to get a substring from a string stored in a variable. I tried sed with a bit help from this forum, but not successful. Here is my problem. My string is: "REPLYFILE=myfile.txt" And I need: myfile.txt (everything after the = symbol). My string is: "myfile.txt.gz.20091120.enc... (5 Replies)
Discussion started by: jamjam10k
5 Replies

8. Shell Programming and Scripting

AWK: read values from file1; search for values in file2

I have read another post about this issue and am wondering how to adapt it to my own, much simpler, issue. I have a file of user IDs like so: 333333 321321 546465 ...etc I need to take each number and use it to print records wherein the 5th field matches the user ID pulled from the... (2 Replies)
Discussion started by: Bubnoff
2 Replies

9. Shell Programming and Scripting

How to pick values from column based on key values by usin AWK

Dear Guyz:) I have 2 different input files like this. I would like to pick the values or letters from the inputfile2 based on inputfile1 keys (A,F,N,X,Z). I have done similar task by using awk but in that case the inputfiles are similar like in inputfile2 (all keys in 1st column and values in... (16 Replies)
Discussion started by: repinementer
16 Replies

10. UNIX for Dummies Questions & Answers

substring using AWK

can we do substring fuctionality using AWK say I have string "sandeep" can i pick up only portion "nde" from it. Thanks and Regards Sandeep Ranade (3 Replies)
Discussion started by: mahabunta
3 Replies
Login or Register to Ask a Question