Sponsored Content
Top Forums Shell Programming and Scripting Using Awk in shell script to extract an index of a substring from a parent string Post 302144284 by sandeepms17 on Wednesday 7th of November 2007 06:18:43 AM
Old 11-07-2007
Data 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 achieve this

when i excecute this in command line
awk 'BEGIN { print index("Attempting to connect to ipaddr: 127.0.0.1 IllegalUrl_110707092804.txt Succeeded with no errors.","Succeeded with no errors") }'
72

if gives me correct output which is 72

but in shell script it always returns 0.

$a="Attempting to connect to ipaddr: 127.0.0.1 IllegalUrl_110707092804.txt Succeeded with no errors."

$b="Succeeded with no errors"

echo "`awk 'BEGIN { print index($a,$b) }'` "

Can anybody please tell what is the problem or suggest an alternate approach.

Many Thanks,

Sandeep
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

command/script to extract a substring from a string

I have a long string "<ID type="Oid">{}</ID>" I need to extract "GigabitEthernet0/1" from the above string. How can it be done? :) (5 Replies)
Discussion started by: girisha
5 Replies

2. Shell Programming and Scripting

help for shell script of finding shortest substring from given string by user

please give me proper solution for finding a shortest substring from given string if string itself and first char and last char of that substr are also given by user if S="dpoaoqooroo" and FC="o" and LC="o",then shortest substr is "oo" and rest of the string is "dpoaoqroo" i have code but it is... (1 Reply)
Discussion started by: pankajd
1 Replies

3. UNIX for Dummies Questions & Answers

Extract substring of unknown length from string

I have a string: hgLogOutput=" +0000 files: forum/web/hook-test.txt /forum/web/hook-test-2.txt description: test" and I want to extract the file names from it, they will always appear between the files: and the description:. I have worked out that I can do this: "$hgLogOutput" | awk '{... (2 Replies)
Discussion started by: klogger
2 Replies

4. Solaris

Extract substring from a string

i have srtring i.e. "NAME,CLASS,AGE" (length of string is not constant) and from this string i've extract each word delimited by "," (comma). INPUT: "NAME,CLASS,AGE" OUTPUT: NAME CLASS AGE how can i do that? i have tried some string manipulation function like... (5 Replies)
Discussion started by: jadoo_c2
5 Replies

5. Shell Programming and Scripting

Extract a string up to the first occurence of a substring

Hi, I'm a newbie to shell scripting and have searched the forum but couldn't find what i was looking for. Basically I have a list of filenames like... 123-fileone.txt I want to be able to extract the prefix up to the first '-'. So I'd end up with 123. I have attempted it using a pretty... (2 Replies)
Discussion started by: kirkg
2 Replies

6. Shell Programming and Scripting

Extract string in shell script

Hi All, i've a string /u/asak/DATE/TEST_LOGS/20110704_033429_test11_w_2_120/HDD/test11_w_2_12/hd-120 i need to extract string which is test11_w_2_120, this can be start with anything, numbers, characters with underscore etc.. but the time stamp 20110704_033429_ with two underscores will be... (5 Replies)
Discussion started by: asak
5 Replies

7. Shell Programming and Scripting

How to extract a substring from a string

Hi, I have an input string say for example: ABC,DEF,IJK,LMN,...,XYZ The above string is comma delimited. Now I have to extract the last part after the comma i.e. XYZ. :b: (3 Replies)
Discussion started by: bghosh
3 Replies

8. Shell Programming and Scripting

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? awk --re-interval '{if($0 ~ /{1}{2}/) {print FILENAME, substr($0,index($0,/{1}{2}/) , 4)}}'input abcdefg sdlfkj 3,29 g. lasdfj alsdfjasl 2.86 gr. slkjds sldkd lskdjfsl sdfkj kdjlksj 3,34 g... (4 Replies)
Discussion started by: sdf
4 Replies

9. Shell Programming and Scripting

Extract a substring using SED/AWK

Hi All, I have a log file in which name and version of applications are coming in the following format name It may look like following, based on the name of the application and version: XYZ OR xyz OR XyZ OR xyz I want to separate out the name and version and store them into variables.... (4 Replies)
Discussion started by: bhaskar_m
4 Replies

10. Shell Programming and Scripting

Script Shell Extract substring

Hi all, Please, i'd like to extract string just before '.fr'. Here is some lines of my file: g-82.text.text1.fr.worker1 g-xx.yyyyyy.zzzz.fr.worker2 i'd like to extract this text: g-82.text.text1 g-xx.yyyyyy.zzzz Please, which command i have to use in my script shell ? ... (16 Replies)
Discussion started by: chercheur111
16 Replies
XtCreatePopupShell(3)                                              XT FUNCTIONS                                              XtCreatePopupShell(3)

NAME
XtCreatePopupShell, XtVaCreatePopupShell - create a popup shell SYNTAX
Widget XtCreatePopupShell(String name, WidgetClass widget_class, Widget parent, ArgList args, Cardinal num_args); Widget XtVaCreatePopupShell(String name, WidgetClass widget_class, Widget parent, ...); ARGUMENTS
args Specifies the argument list to override the resource defaults. name Specifies the text name for the created shell widget. num_args Specifies the number of arguments in the argument list. parent Specifies the parent widget. widget_class Specifies the widget class pointer for the created shell widget. ... Specifies the variable argument list to override the resource defaults. DESCRIPTION
The XtCreatePopupShell function ensures that the specified class is a subclass of Shell and, rather than using insert_child to attach the widget to the parent's children list, attaches the shell to the parent's pop-ups list directly. A spring-loaded pop-up invoked from a translation table already must exist at the time that the translation is invoked, so the translation manager can find the shell by name. Pop-ups invoked in other ways can be created ``on-the-fly'' when the pop-up actually is needed. This delayed creation of the shell is particularly useful when you pop up an unspecified number of pop-ups. You can look to see if an appropri- ate unused shell (that is, not currently popped up) exists and create a new shell if needed. SEE ALSO
XtCreateWidget(3), XtPopdown(3), XtPopup(3) X Toolkit Intrinsics - C Language Interface Xlib - C Language X Interface X Version 11 libXt 1.1.3 XtCreatePopupShell(3)
All times are GMT -4. The time now is 01:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy