Sponsored Content
Top Forums Shell Programming and Scripting Extract First and matching word from string in UNIX Post 302844356 by krishmaths on Monday 19th of August 2013 02:31:30 AM
Old 08-19-2013
Code:
 awk '{a=$1;} gsub(/\(/, " (") gsub(/\)/, " )") {for(i=2;i<=NF;i++) {if(substr($i,1,5)=="$dwh.") a=a" "substr($i,6)}} {print a}' file.sql

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl newbie: how to extract an unknown word from a string

hi, im quite new to perl regexp. i have a problem where i want to extract a word from a given string. but the word is unknown, only fact is that it appears as the second word in the string. Eg. input string(s) : char var1 = 'A'; int var2 = 10; char *ptr; and what i want to do is... (3 Replies)
Discussion started by: wolwy_pete
3 Replies

2. Shell Programming and Scripting

Extract single or multi word string in Cshell

I am using the following code: set LASInputFile = `ls *. | head -1` set COMPLine = `grep -i :COMPANY $LASInputFile` to extract the following line from my input file: COMP. XYZ Public Company :COMPANY NAME I now need to extract the full name of the company which... (15 Replies)
Discussion started by: phudgens
15 Replies

3. Shell Programming and Scripting

Search string in unix and print whole matching word

Hi I have requirement to search string starting with specific characters and print whole matching word in that string. example mystr="ATTRIBUTE NAME="Event Name" VALUE="Execute"" I want to search by passing "NAME=" and result should be NAME="Event Name". i am using below command but... (3 Replies)
Discussion started by: tmalik79
3 Replies

4. Shell Programming and Scripting

Using SED to extract a word or string.

I am working with the ksh shell in HP UNIX and I am attempting to extract a word, beginning with a particular string and ending at the first space. for example I want to extract the word or string MS_RECENT_ACTIVITY from the following string " This has been entered in MS_RECENT_ACTIVITY the... (2 Replies)
Discussion started by: simpletech369
2 Replies

5. Shell Programming and Scripting

how to extract last word and a number from a string

I have the following script (which I made by my self) #!/bin/bash # add a few empty lines to make it more legible # add a date description on each update interval echo "" >> /home/user/DYN_DNS_IP_change.log echo "" >> /home/user/DYN_DNS_IP_change.log echo "" >>... (6 Replies)
Discussion started by: mahirzukic2
6 Replies

6. Shell Programming and Scripting

Extract a string from another string in UNIX

I have a string string="Please have a nice day and sleep well Replace_12123_31233_32134_12342 Good day" How do i replace "Replace_12123_31233_32134_1234" in the above string.?? Please help. Regards, Qwerty (3 Replies)
Discussion started by: qwertyu
3 Replies

7. Shell Programming and Scripting

Command to extract word from a string

Hi All, I have a word and from that word would like to search for certain set of string, is there any command to do so ? EX : Components from the above word, would like to search for strings set and extract the search string and then do if stmt... pon nen ent Com say... (2 Replies)
Discussion started by: Optimus81
2 Replies

8. Shell Programming and Scripting

Extract all text between the same matching string from a given column

Hello All, I have an input sample data like below (In actual I have many columns and few million rows). Column1,Column2 4,2 1,5 Hello,4 1,4 Hello,2 3,5 Hello,8 4,5 Need the output (using awk and/or sed preferably) like below. Here I need all the lines between 2 matching... (1 Reply)
Discussion started by: ks_reddy
1 Replies

9. Shell Programming and Scripting

How can I extract XML block around matching search string?

I want to extract XML block surrounding search string Ex: print XML block for string "myapp1-ear" surrounded by "<application> .. </application>" Input XML: <?xml version="1.0" encoding="UTF-8"?> <deployment-request> <requestor> <first-name>kchinnam</first-name> ... (16 Replies)
Discussion started by: kchinnam
16 Replies

10. UNIX for Beginners Questions & Answers

Get string before specific word in UNIX

Hi All, I'm writing unix shell script and I have these files. I need to get name before _DETL.tmp. ABC_AAA_DETL.tmp ABC_BBB_DETL.tmp ABC_CCC_DETL.tmp PQR_DETL.tmp DEF_DETL.tmp JKL_DETL.tmp YUI_DETL.tmp TG_NM_DDD_DETL.tmp TG_NM_EEE_DETL.tmp GHJ_DETL.tmp RTY_DETL.tmp output will... (3 Replies)
Discussion started by: ace_friends22
3 Replies
GLOB(7) 					       BSD Miscellaneous Information Manual						   GLOB(7)

NAME
glob -- shell-style pattern matching DESCRIPTION
Globbing characters (wildcards) are special characters used to perform pattern matching of pathnames and command arguments in the csh(1), ksh(1), and sh(1) shells as well as the C library functions fnmatch(3) and glob(3). A glob pattern is a word containing one or more unquoted '?' or '*' characters, or ``[..]'' sequences. Globs should not be confused with the more powerful regular expressions used by programs such as grep(1). While there is some overlap in the special characters used in regular expressions and globs, their meaning is different. The pattern elements have the following meaning: ? Matches any single character. * Matches any sequence of zero or more characters. [..] Matches any of the characters inside the brackets. Ranges of characters can be specified by separating two characters by a '-' (e.g. ``[a0-9]'' matches the letter 'a' or any digit). In order to represent itself, a '-' must either be quoted or the first or last character in the character list. Similarly, a ']' must be quoted or the first character in the list if it is to represent itself instead of the end of the list. Also, a '!' appearing at the start of the list has special meaning (see below), so to represent itself it must be quoted or appear later in the list. Within a bracket expression, the name of a character class enclosed in '[:' and ':]' stands for the list of all characters belonging to that class. Supported character classes: alnum cntrl lower space alpha digit print upper blank graph punct xdigit These match characters using the macros specified in ctype(3). A character class may not be used as an endpoint of a range. [!..] Like [..], except it matches any character not inside the brackets. Matches the character following it verbatim. This is useful to quote the special characters '?', '*', '[', and '' such that they lose their special meaning. For example, the pattern ``\*[x]?'' matches the string ``*[x]?''. Note that when matching a pathname, the path separator '/', is not matched by a '?', or '*', character or by a ``[..]'' sequence. Thus, /usr/*/*/X11 would match /usr/X11R6/lib/X11 and /usr/X11R6/include/X11 while /usr/*/X11 would not match either. Likewise, /usr/*/bin would match /usr/local/bin but not /usr/bin. SEE ALSO
fnmatch(3), glob(3), re_format(7) HISTORY
In early versions of UNIX, the shell did not do pattern expansion itself. A dedicated program, /etc/glob, was used to perform the expansion and pass the results to a command. In Version 7 AT&T UNIX, with the introduction of the Bourne shell, this functionality was incorporated into the shell itself. BSD
November 30, 2010 BSD
All times are GMT -4. The time now is 12:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy