Sponsored Content
Top Forums Shell Programming and Scripting Getting the index of a string in a string Post 302739803 by pamu on Wednesday 5th of December 2012 02:16:30 AM
Old 12-05-2012
Use sth like this..

Code:
line="Some text with ERR message"
index=$(echo $line | awk '{for(i=1;i<=NF;i++) if($i~/^ERR/){print i}}')
echo $index

This User Gave Thanks to pamu For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find first digit in string using expr index

I have looked for hours for an answer, so I have decided to request your guidance. I want to substract the first number (series of digits) contained in a string. This string is the output of another command. The substring (number) can be located at any position inside the string. I want to... (4 Replies)
Discussion started by: jcd
4 Replies

2. Shell Programming and Scripting

Problem when assign the array with the string index

I come across the problems when assigning the array in the script below . How to use the array with the 'string index' correctly ? When I assign a new string index , the array elements that are previously assigned are all changed .:eek::eek::eek: $ array=211 $ echo ${array} 211 $... (4 Replies)
Discussion started by: youareapkman
4 Replies

3. Shell Programming and Scripting

Find index of last occurence of a character within a string

I need to find the index of last '|' (highlighted in bold) in awk : |ifOraDatabase.Lastservererr<>0then|iferr_flag<>0then|end if Please suggest a way... Thanks (5 Replies)
Discussion started by: joyan321
5 Replies

4. UNIX for Dummies Questions & Answers

string index

I have a line "My name is Deepak" How can i search a string Deepak in the line and find out its index position. Here in this case the result should be 12. (3 Replies)
Discussion started by: dr46014
3 Replies

5. Shell Programming and Scripting

Finiding filenames with specific index string

Hi All, I have a file (Names.txt) and the contents of the file is give below. $ cat Names.txt FF313207008.txt FF223207007.txt FF143207006.txt FF372150600.txt FF063407005.txt FF063307005.txt $ From these given file names I want to find the files which has the 6th index value as 2. So... (5 Replies)
Discussion started by: krish_indus
5 Replies

6. UNIX for Dummies Questions & Answers

how to get index/postion of a string?

Hi, I have a string like the following: /db1/data/GLIDER/SYSTEM.dbf need to find the postion where "SYSTEM.dbf" starts, so I tried: LOCATION=/db1/data/GLIDER/SYSTEM.dbf $ expr index $LOCATION SYSTEM expr: syntax error $ expr index "$LOCATION" SYSTEM expr: syntax error ... (5 Replies)
Discussion started by: seafan
5 Replies

7. Shell Programming and Scripting

check index of a string by finding a letter in it

i would like to search for a letter in a string and get its index position. example: name='john' pos=$(expr index $name o) the result will be equal to 2 (2nd position) how do you make this thing not case sensitive? example: name='john' pos=$(expr index $name O) the... (1 Reply)
Discussion started by: kokoro
1 Replies

8. Shell Programming and Scripting

To cut a string based on last index of identifier

here below is sample string null pointer dereference of 'resourceList' where null is returned from a method/opt/bld/fetch/ds/interzone/notification/LocalLineStatusNotificationListener.java:79 null pointer dereference of 'reList' where null is returned from a... (3 Replies)
Discussion started by: vivek d r
3 Replies

9. Shell Programming and Scripting

Substitute string with an index number

Objective is to substitute Jan with 01, Feb with 02 and so on. The month will be provided as input. I could construct below awk and it worked. echo Jun | \ awk 'BEGIN{split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec",mon," ")}{ for (i=1;i<=12;i++){ if ($1==mon) printf("%02d\n",i)} }' ... (4 Replies)
Discussion started by: krishmaths
4 Replies

10. Shell Programming and Scripting

Comparing the value of a string index to a variable.

Hi, coding a simple program to compare an entered number to a randomly generated one. The number of digits are restricted so I'm just trying to figure out how to refer to the index value in a string and then compare it to the variable I want. I don't know if bash automatically indexes strings, so... (7 Replies)
Discussion started by: outofcookies
7 Replies
DBIx::ContextualFetch(3pm)				User Contributed Perl Documentation				DBIx::ContextualFetch(3pm)

NAME
DBIx::ContextualFetch - Add contextual fetches to DBI SYNOPSIS
my $dbh = DBI->connect(...., { RootClass => "DBIx::ContextualFetch" }); # Modified statement handle methods. my $rv = $sth->execute; my $rv = $sth->execute(@bind_values); my $rv = $sth->execute(@bind_values, @bind_cols); # In addition to the normal DBI sth methods... my $row_ref = $sth->fetch; my @row = $sth->fetch; my $row_ref = $sth->fetch_hash; my %row = $sth->fetch_hash; my $rows_ref = $sth->fetchall; my @rows = $sth->fetchall; my $rows_ref = $sth->fetchall_hash; my @tbl = $sth->fetchall_hash; DESCRIPTION
It always struck me odd that DBI didn't take much advantage of Perl's context sensitivity. DBIx::ContextualFetch redefines some of the various fetch methods to fix this oversight. It also adds a few new methods for convenience (though not necessarily efficiency). SET-UP my $dbh = DBIx::ContextualFetch->connect(@info); my $dbh = DBI->connect(@info, { RootClass => "DBIx::ContextualFetch" }); To use this method, you can either make sure that everywhere you normall call DBI->connect() you either call it on DBIx::ContextualFetch, or that you pass this as your RootClass. After this DBI will Do The Right Thing and pass all its calls through us. EXTENSIONS
execute $rv = $sth->execute; $rv = $sth->execute(@bind_values); $rv = $sth->execute(@bind_values, @bind_cols); execute() is enhanced slightly: If called with no arguments, or with a simple list, execute() operates normally. When when called with two array references, it performs the functions of bind_param, execute and bind_columns similar to the following: $sth->execute(@bind_values); $sth->bind_columns(undef, @bind_cols); In addition, execute will accept tainted @bind_values. I can't think of what a malicious user could do with a tainted bind value (in the general case. Your application may vary.) Thus a typical idiom would be: $sth->execute([$this, $that], [($foo, $bar)]); Of course, this method provides no way of passing bind attributes through to bind_param or bind_columns. If that is necessary, then you must perform the bind_param, execute, bind_col sequence yourself. fetch $row_ref = $sth->fetch; @row = $sth->fetch; A context sensitive version of fetch(). When in scalar context, it will act as fetchrow_arrayref. In list context it will use fetchrow_array. fetch_hash $row_ref = $sth->fetch_hash; %row = $sth->fetch_hash; A modification on fetchrow_hashref. When in scalar context, it acts just as fetchrow_hashref() does. In list context it returns the complete hash. fetchall $rows_ref = $sth->fetchall; @rows = $sth->fetchall; A modification on fetchall_arrayref. In scalar context it acts as fetchall_arrayref. In list it returns an array of references to rows fetched. fetchall_hash $rows_ref = $sth->fetchall_hash; @rows = $sth->fetchall_hash; A mating of fetchall_arrayref() with fetchrow_hashref(). It gets all rows from the hash, each as hash references. In scalar context it returns a reference to an array of hash references. In list context it returns a list of hash references. ORIGINAL AUTHOR
Michael G Schwern as part of Ima::DBI CURRENT MAINTAINER
Tony Bowden <tony@tmtm.com> LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
DBI. Ima::DBI. Class::DBI. perl v5.10.0 2005-09-27 DBIx::ContextualFetch(3pm)
All times are GMT -4. The time now is 03:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy