Sponsored Content
Top Forums Shell Programming and Scripting Extract whole word preceding a specific character pattern with first occurence of the pattern Post 303038960 by RavinderSingh13 on Wednesday 18th of September 2019 10:28:28 AM
Old 09-18-2019
Hello jcdole,

Yes, that could be shorten to following.
Code:
MY_PATTERN="="
SOME_VAR=$(awk -F"$MY_PATTERN" '{split($1,array," ");print array[3]}' Input_file)
echo "$SOME_VAR"

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
 

10 More Discussions You Might Find Interesting

1. HP-UX

extract field of characters after a specific pattern - using UNIX shell script

Hello, Below is my input file's content ( in HP-UX platform ): ABCD120672-B21 1 ABCD142257-002 1 ABCD142257-003 1 ABCD142257-006 1 From the above, I just want to get the field of 13 characters that comes after 'ABCD' i.e '120672-B21'... . Could... (2 Replies)
Discussion started by: jansat
2 Replies

2. Shell Programming and Scripting

Extract specific pattern from a file

Hi All, I am a newbie to Shell Scripting. I have a File The Server Name XXX002 ------------------------- 2.1 LAPD Iface Id Link MTU Side ecc_3_1 4 Up 512 User ecc_3_2 5 Up 512 User The Server Name XXX003 ------------------------- 2.1 LAPD (4 Replies)
Discussion started by: athreyavc
4 Replies

3. Shell Programming and Scripting

Need to extract specific pattern from logfile

Log File: Attempting to contact (DESCRIPTION=(SOURCE_ROUTE=OFF)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname1.com)(PORT=1521)))(CONNECT_DATA=(SID=database1)(SRVR=DEDICATED))) Attempting to contact... (2 Replies)
Discussion started by: techychap
2 Replies

4. Shell Programming and Scripting

How to identify the occurence of a pattern between a unique character?

hi, is it possible to find the number of occurences of a pattern between two paranthesis. for e.g i have a file as below. >>{ >>hi >>GoodMorning >>how are you? >>} >>is it good, >>tell me yes, if it is good In the above file, its clear the occurence of word "Good"... (17 Replies)
Discussion started by: divak
17 Replies

5. Shell Programming and Scripting

extract specific line if the search pattern is found

Hi, I need to extract <APPNUMBER> tag alone, if the <college> haas IIT Chennai value. college tag value will have spaces embedded. Those spaces should not be suppresses. My Source file <Record><sno>1</sno><empid>E0001</empid><name>Rejsh suderam</name><college>IIT ... (3 Replies)
Discussion started by: Sekar1
3 Replies

6. UNIX for Dummies Questions & Answers

Search specific pattern in file and return number of occurence

Hi I want to search for a specific pattern in file Say ABC;HELLO_UNIX_WORLD;PQR ABC;HELLO_UNIX_WORLD_IS_NOT_ENOUGH;XYZ ABC;HELLO_UNIX_FORUM;LMN Pattern to search is : "HELLO_UNIX_*****" and not "HELLO_UNIX_***_***_" I mean after "HELLO_UNIX" there can only be one word.In this case... (2 Replies)
Discussion started by: dashing201
2 Replies

7. Shell Programming and Scripting

Extract Specific pattern - log file

Hello everyone, I am on AIX (6.1). I can only use shell (ksh) script. I can't do this on my own, so will do my best to explain my needs.I also do not know what is the best idea to make it work, so here is what I am thinking, but I may wrong. I need help to extract info on... (3 Replies)
Discussion started by: Aswex
3 Replies

8. Shell Programming and Scripting

Getting value of a pattern preceding another pattern

I have a file like this ------------------------------- -------------------------------------- I need a way to find the timestamp preceding the ERR-XXXXX Here XXXX deonoes any any numeric string 00000-99999 that is a output like this 2012-11-12 : 11:59-ERR-XXXXX 2012-11-12 : ... (4 Replies)
Discussion started by: swayam123
4 Replies

9. Shell Programming and Scripting

Extract specific line in an html file starting and ending with specific pattern to a text file

Hi This is my first post and I'm just a beginner. So please be nice to me. I have a couple of html files where a pattern beginning with "http://www.site.com" and ending with "/resource.dat" is present on every 241st line. How do I extract this to a new text file? I have tried sed -n 241,241p... (13 Replies)
Discussion started by: dejavo
13 Replies

10. Post Here to Contact Site Administrators and Moderators

Search for a pattern and replace a space at specific position with a Character in File

In file, we have millions of records each of 1000 in length. And at specific position say 800 there is a space, we need to replace it with Character X if the ID in that row starts with 123. So far i have used the below which is replacing space at that position to X but its not checking for... (3 Replies)
Discussion started by: Jagmeet Singh
3 Replies
SHELLEXP(3)						     Library Functions Manual						       SHELLEXP(3)

NAME
shellexp - match string against a cruft filter pattern SYNOPSIS
extern int shellexp(const char *string, const char *pattern); DESCRIPTION
The shellexp() function is similar to fnmatch(3), but works with cruft patterns instead of standard glob(7) patterns. The function returns a true value if string matches the cruft pattern pattern, and a false value (0) otherwise. Returns -1 in case of pattern syntax error. Cruft patterns are similar to glob(7) patterns, but are not fully compatible. The following special characters are supported: ? (a question mark) matches exacly one character of string other than a slash. * matches zero or more characters of string other than a slash. /** or /**/ matches zero or more path components in string. Please note that you can only use ** when directly following a slash, and further- more, only when either directly preceding a slash or at the very end of pattern. A ** followed by anything other than a slash makes pattern invalid. A ** following anything else than a slash reduces it to having the same effect as *. [character-class] Matches any character between the brackets exactly once. Named character classes are NOT supported. If the first character of the class is ! or ^, then the meaning is inverted (matches any character NOT listed between the brackets). If you want to specify a literal closing bracket in the class, then specify it as the first (or second, if you want to negate) character after the opening bracket. Also, simple ASCII-order ranges are supported using a dash character (see examples section). Any other character matches itself. EXAMPLES
/a/b*/*c matches /a/b/xyz.c, as well as /a/bcd/.c, but not /a/b/c/d.c. /a/**/*.c matches all of the following: /a/a.c, /a/b/a.c, /a/b/c/a.c and /a/b/c/d/a.c. /a/[0-9][^0-9]* matches /a/1abc, but not /a/12bc. BUGS
Uses constant-length 1000 byte buffers to hold filenames. Also uses recursive function calls, which are not very efficient. Does not vali- date the pattern before matching, so any pattern errors (unbalanced brackets or misplaced **) are only reported when and if the matching algorithm reaches them. SEE ALSO
fnmatch(3), glob(3), cruft(8) and dash-search(1). AUTHOR
This manual page was written by Marcin Owsiany <porridge@debian.org>, for the Debian GNU/Linux system (but may be used by others). October 17, 2007 SHELLEXP(3)
All times are GMT -4. The time now is 10:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy