Sponsored Content
Top Forums Shell Programming and Scripting How to grep a pattern having value greater than 123 in a file? Post 302553423 by durden_tyler on Wednesday 7th of September 2011 01:33:41 PM
Old 09-07-2011
Quote:
Originally Posted by herot
how would you do the same thing but only for values before the first "," in each line AND for decimal numbers ie 400.232352,ATK4875739,234,2,33,3?
Code:
$
$
$ cat f18
400.232352,ATK4875739,234,2,33,3  # show, because no. from beginning to 1st comma is decimal and > 123
100.23,XYZ,0                      # don't show, because no. from beginning to 1st comma is decimal but < 123
125,ABC,0                         # don't show, because no. from beginning to 1st comma is not a decimal
12PQR,DEF,0                       # don't show, because chars from beginning to 1st comma do not represent a number
123.000001,ATK4875739,234,2,33,3  # show, because no. from beginning to 1st comma is decimal and > 123
-100.23,MNO,0                     # don't show, because no. from beginning to 1st comma is decimal but < 123
$
$
$ perl -lne '/^(.*?),.*/; print if $1 !~ /[a-zA-Z]/ and int($1) != $1 and $1 > 123' f18
400.232352,ATK4875739,234,2,33,3  # show, because no. from beginning to 1st comma is decimal and > 123
123.000001,ATK4875739,234,2,33,3  # show, because no. from beginning to 1st comma is decimal and > 123
$
$
$

tyler_durden
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Grep a pattern in gz file

I have a set of .gz files. I need to grep a pattern and need to find out the file in which that pattern occurs. zgrep in not available in my server.Any other options available for searching a pattern without unzipping the .gz files. (2 Replies)
Discussion started by: rprajendran
2 Replies

2. Shell Programming and Scripting

grep for greater than 12 chars

Hi, is there any way in grep to grep for a certain number of characters? For example I have a list of customerIDs, I want to grep for all greater than 12 characters? (2 Replies)
Discussion started by: borderblaster
2 Replies

3. Shell Programming and Scripting

Need to Grep or awk a logfile for greater than value

Hello all Hoping someone would be kind enough to suggest a solution to a problem i have, and see if maybe i can even do this without a script. Essentially i have a very large log file, and within it each line had a value called TTMT, and it records a variable number in the following way, so... (6 Replies)
Discussion started by: 1905
6 Replies

4. Shell Programming and Scripting

grep /target greater than time period??

Hey guys, I'm fairly new at unix shell scripting and I have a quick question. Quick overview I devolped a script where I generate a file ..and I want to grep any time greater than 30 minutes. What i do is runa command to generates the below and puts it into a file: I run ./ggsci << endit... (4 Replies)
Discussion started by: nomiezvr4
4 Replies

5. Shell Programming and Scripting

script to grep a pattern from file compare contents with another file and replace

Hi All, Need help on this I have 2 files one file file1 which has several entries as : define service{ hostgroup_name !host1,!host5,!host6,.* service_description check_nrpe } define service{ hostgroup_name !host2,!host4,!host6,.* service_description check_opt } another... (2 Replies)
Discussion started by: namitai
2 Replies

6. UNIX for Dummies Questions & Answers

look for file size greater than "0" of specific pattern and move those to another directory

Hi , i have some files of specific pattern ...i need to look for files which are having size greater than zero and move those files to another directory.. Ex... abc_0702, abc_0709, abc_782 abc_1234 ...etc need to find out which is having the size >0 and move those to target directory..... (7 Replies)
Discussion started by: dssyadav
7 Replies

7. UNIX for Dummies Questions & Answers

Grep lines with numbers greater than 2 digits at the end of the line

I'm trying to grep lines where the digits at the end of each line are greater than digits. Tried this but it will only allow me to specify 2 digits. Any ideas would greatly be appreciated. grep -i '\<\{3,4,5\}\>' file ---------- Post updated at 05:58 PM ---------- Previous update was at 05:41... (1 Reply)
Discussion started by: jimmyf
1 Replies

8. Shell Programming and Scripting

Grep a file pattern in another

Hi I'm new to the forum, so I'd apologize for any error in the format of the post. I'm trying to find a file content in another one using: grep -w -f file1 file2 file1 GJA7 TSC file 2 GJC1 GJA7 TSC1 TSC (11 Replies)
Discussion started by: flyfisherman
11 Replies

9. UNIX for Dummies Questions & Answers

Grep SQL output file for greater than number.

Hi, This is my first post. I have a korn shell script which outputs a select statment to a file. There is only one column and one row which contains a record count of the select statement. The select statement looks something like this: SELECT COUNT(some_field) AS "count_value" ... (2 Replies)
Discussion started by: MurdocUK
2 Replies

10. Shell Programming and Scripting

sed and awk usage to grep a pattern 1 and with reference to this grep a pattern 2 and pattern 3

Hi , I have a file where i have modifed certain things compared to original file . The difference of the original file and modified file is as follows. # diff mir_lex.c.modified mir_lex.c.orig 3209c3209 < if(yy_current_buffer -> yy_is_our_buffer == 0) { --- >... (5 Replies)
Discussion started by: breezevinay
5 Replies
All times are GMT -4. The time now is 10:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy