Sponsored Content
Top Forums Shell Programming and Scripting [awk]compare a number in a string with a list Post 302498492 by sandeepk1611 on Monday 21st of February 2011 01:33:26 PM
Old 02-21-2011
[awk]compare a number in a string with a list

Hi,

I have a program written in awk and I want to extend it to do another task.

My program is a list of CVS log reports of a repository. For each file, I have some fields. One of the fields is the comment field. I want to know how I can check if a comment (which is a free text field) contains a number and if it does, I want to check if that number exists in another list of numbers (taken as input from another file).

For example,
If the list of numbers is
Code:
100
101
102
103

And I have the following log data

Code:
RCS file: /cvsroot/eclipse/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/util/SourcePositionImpl.java,v
head: 1.10
branch:
locks: strict
access list:
keyword substitution: kv
total revisions: 12;    selected revisions: 1
description:
=============================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/util/TypesUtil.java,v
head: 1.13
branch:
locks: strict
access list:
keyword substitution: kv
total revisions: 15;    selected revisions: 2
description:
----------------------------
revision 1.13
date: 2008-01-01 20:28:39 -0600;  author: wharley;  state: Exp;  lines: +1 -16;  commitid: 537d477af6d64567;
Bug 100 - partial fix.  
=============================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/util/Visitors.java,v
head: 1.7
branch:
locks: strict
access list:
keyword substitution: kv
total revisions: 8;    selected revisions: 1
description:
=============================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/util/AptPreferenceConstants.java,v
head: 1.16
branch:
locks: strict
access list:
keyword substitution: kv
total revisions: 17;    selected revisions: 4
description:
----------------------------
revision 1.16
date: 2008-01-29 16:55:45 -0600;  author: wharley;  state: Exp;  lines: +1 -1;  commitid: 69f6479faef04567;
This is also some sample text. bug 101, followed by some more text. 
----------------------------
revision 1.14
date: 2007-10-15 15:46:44 -0500;  author: wharley;  state: Exp;  lines: +12 -1;  commitid: 724c4713d1b24567;
This is some sample text. Bug 102: some text
=============================================================================

After the word "description", there can be 0, 1 or more commit data. In each commit data, I want to get the number from it, which can be anywhere in the 3rd or 4th line after the field separator "----------". And I want to compare that number with the list above and if it turns to be true, take some actions.

Can anyone help me how to do this. If needed, I can also send the already existing awk code I have.

Thanks,
Sandeep
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

String compare with list in shell script

Hi , I am new to shell scripting. below is my requirement : 1) while running my .sh i will pass a string 2) i have to extract a folder name under a /config folder 3) i need to compare a input string in the folder name list 4) if that is true i have to continue my job else i have to... (2 Replies)
Discussion started by: rajinavaneethan
2 Replies

2. Shell Programming and Scripting

awk conditional expression to compare field number and variable value

Hi, I'm trying to compare the value in a field to the value in a variable using awk. This works: awk '$7 == "101"'but this is what I want (and it doesn't work): value=101 awk '$7 == "$value"' Any help or insight on this would be great. Thanks in advance. (1 Reply)
Discussion started by: goodbenito
1 Replies

3. Shell Programming and Scripting

Compare strings between 2 arrays and print number in AWK

Hi to everyone, Please some help over here. Hi have array a with 6 elements and array b with 3 elements as shown inside BEGIN{} statement. I need help to get the correct sintax (the part in red) to compare if string from array b is in array a and print the number related for each match.... (3 Replies)
Discussion started by: Ophiuchus
3 Replies

4. Shell Programming and Scripting

awk to compare hex number

$ awk 'BEGIN{ pat111=0x1000000002E3E02; snBegin=0x1000000002E3E01; if (pat111<=snBegin) printf "a\n"}' a Result is not correct. Looks like the number is too big. Any idea? Thx! Please use code tags <- click the link! (2 Replies)
Discussion started by: carloszhang
2 Replies

5. Shell Programming and Scripting

awk if statement to evaluate string and compare

I have the following simplified code that I am planning on putting into a larger shell script. I have been butchering it to try and make work amongst google searches and reading awk documentation. amixer sset Master toggle | awk '{ if ( /^ Front Left/ { print $7 } == // ) print "MUTED" }'I... (2 Replies)
Discussion started by: jelloir
2 Replies

6. Shell Programming and Scripting

awk - how to compare part of the string?

Need help for awk.. file will have comma separated numbers, I need check digits before 10 numbers eg ( 001)1234567890 Basically want to check country code of a mobile number. eg: abc,def,data, data,0011234567890, data,data Script should be checking country code with 001, I will pass... (10 Replies)
Discussion started by: vegasluxor
10 Replies

7. Shell Programming and Scripting

String compare using awk - what am I doing wrong?

Hi all, I was doing some string manipulation in my script and wanted to try using awk. However, I have been stuck with string compare. A simplified form of my conundrum is given below: The below prints expected result (prints "Completed because that is the second element"): $ echo... (5 Replies)
Discussion started by: faraway
5 Replies

8. Shell Programming and Scripting

Pass column number as variable to awk and compare with a string.

Hi All, I have a file test.txt. Content of test.txt : 1 vinay se 2 kumar sse 4 kishore tl I am extracting the content of file with below command. awk '$2 ~ "vinay" {print $0}' test.txt Now instead of hardcoding $2 is there any way pass $2 as variable and compare with a... (7 Replies)
Discussion started by: Girish19
7 Replies

9. Shell Programming and Scripting

Compare string length to a number

Hi, I want to compare strings length to a number but i am getting error. I want first name should be length of 8. Please help. #bin !/bin/bash clear echo -n "Enter name " read name IFS=_ ary=($name) for key in "${!ary}"; do echo "$key${ary}"; done ##First name should be equal to 8... (8 Replies)
Discussion started by: rajneesh4U
8 Replies

10. UNIX for Beginners Questions & Answers

Concatenate a string and number and compare that with another string in awk script

I have below code inside my awk script if ( $0 ~ /SVC IN:/ ) { svc_in=substr( $0,23 , 3); if (msg_start == 1 && msg_end == 0) { msg_arr=$0; } } else if ( $0 ~ /^SVC OUT:/ ) { svc_out=substr( $0, 9, 3); if (msg_start == 1 && msg_end == 0) ... (6 Replies)
Discussion started by: bhagya123
6 Replies
JH_COMPILEFEATURES(1)						    Javahelper						     JH_COMPILEFEATURES(1)

NAME
jh_compilefeatures - Compiles eclipse features using pde-build. SYNOPSIS
jh_compilefeatures [debhelperoptions] [options] [--pde-build-dir=dir] [feature[...]] DESCRIPTION
jh_compilefeatures is a javahelper program that handles compiling features using pde-build. These features can be specified either in debian/eclipse.features or via command-line. jh_compilefeatures uses debhelper behind the scenes and are therefore subject to the compat level (e.g. when parsing the eclipse.features file). When specifying the dependencies for a feature, jh_compilefeatures will see if this feature has just been compiled and will use the dependency if it is among the results. This can be used together with debian/eclipse.features. Dependencies are always resolved by first checking if it is a recently built feature and if not, then the system installed eclipse's dropins folders will be checked. Currently jh_compilefeatures do not clean up between builds, which means the dependencies for previous builds are present for the current build. Nevertheless, do not rely on this, as this behavior is subject to change. Note: jh_compilefeatures will not rearrange the build order for you in order to do this. Note: that jh_compilefeatures will not error out if it cannot find a missing dependency. This is due to the underlying builder being unable to detect this. FILES
debian/eclipse.features List the eclipse features to compile and their dependencies. The first item on the line is the feature to compile and the following items are considered dependencies. A dependency can either be a dropins folder or a previous built feature. jh_compilefeatures will find it as long as it is installed in the system eclipse's dropins folder or it has just been compiled. OPTIONS
--pde-build-dir=dir Specifies the directory from where pde-build is to be run. Defauls to "debian/.eclipse_build". --feature-deps=deps A space separated list of dependencies. These dependencies will be used to compile all features passed by command-line. Features read from debian/eclipse.features are unaffected by this. --build-opts=args Pass args to the underlying builder. These options are passed to all features built. This defaults to "-DjavacTarget=1.5 -DjavacSource=1.5" if not set. This can be disabled by passing the empty string. --jvm-args=args Pass args to the JVM. These options are passed to all features built. --orbit-dir=dir Specifies where the Orbit dependencies can be found. This is only needed if the orbit dir is in an unusual location. --pde-build=cmd Use a non-standard pde-build command to compile the features. --pde-args=args Passes args directly to pde-build. Note, jh_compilefeatures have specialised options for some of pde-build options and these should be used whenever possible. These options are passed to all features built. --ignore-java-home Skip the check of JAVA_HOME. Since the underlying builder uses ant (and therefore java), the build should ensure it always uses the expected java implementation. Use this if you (for whatever reason) need to declare the specific java implementation without being able to use JAVA_HOME. Note: You still have to tell the underlying builder which java to use. EXAMPLE
A sample debian/eclipse.features org.eclipse.tm.terminal emf org.eclipse.rse.sdk org.eclipse.tm.terminal depends on "emf", which is expected to be found in eclipse's dropins folder. org.eclipse.rse.sdk on the other hand has no dependencies beyond the eclipse platform. If needed you can also specify a previously built feature as a dependency: org.eclipse.some.feature org.eclipse.another.feature org.eclipse.some.feature rse Here org.eclipse.another.feature depends org.eclipse.some.feature, which was just built and also rse, which is expected to be in system installed eclipse's dropins. SEE ALSO
debhelper(7) This program is a part of javahelper and uses debhelper as backend. There are also tutorials in /usr/share/doc/javahelper. AUTHOR
Niels Thykier <niels@thykier.net> COPYRIGHT AND LICENSE
Copyright 2010 by Niels Thykier This tool is free software; you may redistribute it and/or modify it under the terms of GNU GPL 2. 0.43 2011-03-24 JH_COMPILEFEATURES(1)
All times are GMT -4. The time now is 09:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy