Sponsored Content
Top Forums Shell Programming and Scripting Displaying text till pattern match found in a line Post 302764251 by pamu on Thursday 31st of January 2013 07:39:04 AM
Old 01-31-2013
Code:
 
awk '{for(i=1;i<=NF;i++){if($i ~ /[pP]assed/){s=s?s" "$i:$i; print s;s="";next}else{s=s?s" "$i:$i;}}}' file

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk script to match pattern till blank line

Hi, I need to match lines after a pattern, upto the first blank line. Searched in web and some forums but coulnt find the answer. where <restart_step> = 10 -- Execute query 20 -- Write the contents to the Oracle table 30 -- Writing Contents to OUTPUT... (7 Replies)
Discussion started by: justchill
7 Replies

2. Shell Programming and Scripting

Print characters till the next space when the pattern is found

i have a file which contains alphanumeric data in every line. what i need is the data after certain pattern. the data after the pattern is not of fixed length so i need the data till the space after the pattern. Input file: bfdkasfbdfg khffkf lkdhfhdf pattern (datarequired data not required)... (2 Replies)
Discussion started by: gpk_newbie
2 Replies

3. Shell Programming and Scripting

Grep the word from pattern line and update in subsequent lines till next pattern line reached

Hi, I have got the below requirement. please suggest. I have a file like, Processing Item is: /data/ing/cfg2/abc.txt /data/ing/cfg3/bgc.txt Processing Item is: /data/cmd/for2/ght.txt /data/kernal/config.klgt.txt I want to process the above file to get the output file like, ... (5 Replies)
Discussion started by: rbalaj16
5 Replies

4. Shell Programming and Scripting

Pattern match till the end of the file.

I have a file which is like this ……………………………………….. ………………………………… ………………………………… …………………………………… ……………………………………. ……………………………… <<<from_here>>> ……………………………… ………………………………. I want a script which would fetch the data starting from <<<from_here>>> in the file till the end... (2 Replies)
Discussion started by: halfafringe
2 Replies

5. Shell Programming and Scripting

To add a new line with specific text after the pattern is found using sed

hi guys, im trying to add the following line in my xml file <dbrollbacksegs <oa_var="s_db_rollback_segs">NOROLLBACK</dbrollbacksegs> when ever i find the following line <dbsharedpool oa_var="s_dbsharedpool_size">300000000</dbsharedpool> I have succedded till adding a new line... (1 Reply)
Discussion started by: smarlaku
1 Replies

6. Shell Programming and Scripting

If first pattern is found, look for second pattern. If second pattern not found, delete line

I had a spot of trouble coming up with a title, hopefully you'll understand once you read my problem... :) I have the output of an ldapsearch that looks like this: dn: cn=sam,ou=company,o=com uidNumber: 7174 gidNumber: 49563 homeDirectory: /home/sam loginshell: /bin/bash uid: sam... (2 Replies)
Discussion started by: samgoober
2 Replies

7. UNIX for Dummies Questions & Answers

Shell Script for displaying the line till the target word

" Script for display sentences with special character" Hi, Could any one share a command how to display a line until my target word. For ex: My file has the content as: select * from db_wrk where col1 < col2 insert into table_name values('1','2','tst','wrk','dev','prod') My target... (10 Replies)
Discussion started by: Kalaiselvi66
10 Replies

8. Shell Programming and Scripting

Append text on particular line after pattern found

hi, i have /etc/inittab, I want to add another line after that when i find a pattern "l6:6:wait:/etc/rc.d/rc 6". original l6:6:wait:/etc/rc.d/rc 6 after-change l6:6:wait:/etc/rc.d/rc 6 /sbin/if-pp-to-cng (3 Replies)
Discussion started by: learnbash
3 Replies

9. Shell Programming and Scripting

Rearrange or replace only the second line after pattern match or pattern match

Im using the command below , but thats not the output that i want. it only prints the odd and even numbers. awk '{if(NR%2){print $0 > "1"}else{print $0 > "2"}}' Im hoping for something like this file1: Text hi this is just a test text1 text2 text3 text4 text5 text6 Text hi... (2 Replies)
Discussion started by: invinzin21
2 Replies

10. UNIX for Beginners Questions & Answers

Modify text file if found multiple pattern match for every line.

Looking for help, i have input file like below and want to modify to expected output, if can without create additional file, hope can direct modify it. have 2 thing need do. 1st is adding a word (testplan generation off) after ! ! IPG: Tue Aug 07 14:31:17 2018 2nd is adding... (16 Replies)
Discussion started by: kttan
16 Replies
match(1)							Mail Avenger 0.8.3							  match(1)

NAME
match - Match strings against glob paterns SYNOPSIS
match [-gilrqs] [-n <n>] [-c cmd] [-x code] {[-p] pattern | -f <file>} str1 [str2 ...] DESCRIPTION
match checks strings against pattern, which should be a shell-like glob pattern. pattern may contain the following special characters: ? A "?" character in pattern matches any single character in the string, except that the "/" character is only matched if match was given the -s option. * A "*" character in pattern matches zero or more characters in the string. The exception is that it will only match "/" characters if match was given the -s option. [...] A set of characters between square brackets matches any character in the set. In addition, the "-" character can be used to specify a range. For example "[+e0-3]" would match any of the characters "+", "e", 0, 1, 2, or 3 in the input string. To include a hyphen ("-") in the set of characters matched, either include the hyphen first or last, or escape it with a "". [!...] A character class preceded by a "!" matches any character but those specified in the class. The exception is that the negated character class will match a "/" only if match was given the -s option. c The backslash character escapes the next character c. Thus, to match a literal "*", you would use the pattern "*". match prints each string that matches pattern, one per line, and exits 0 if one or more strings matched. If no string matches, match exits with status 67 (or whatever alternate status was specified by the -x flag). If the -n n flag was specified, match prints only the text that matched the nth occurrence of "*" in the patten. OPTIONS -f file Specifies that the pattern should be read from file. match will read each line of the file and consider it as pattern to match against the argument strings. For each argument string, match stops when it hits the first matching line of the file. If file does not exist, match exits 67, or whatever code was specified by -x. -g Normally, the -n option selects text matching particular "*" characters in the patern. -g changes this behavior to use parentheses for grouping. Thus, for instance, the text "foo.c" would match pattern "*(.[ch])", and the output with option -n 1 would be ".c". To include a literal "(" or ")" in the pattern with the -g option, you must precede the character with a "". -i Makes the match case insensitive. str will be considered to match if any variation on its capitalization would match. For example, string "G" would match pattern "[f-h]". -l When a pattern matches the string in more than one way, the -l flag says to assign as much text as possible to the leftmost "*"s in the pattern. For example, pattern "*+*" would match text "a+b+c", and the first "*" would match "a+b". This behavior is the default, thus -l's effect is only to undo a previous -r flag. -n n With this flag, match prints the text that matched the nth "*" in the pattern, as opposed to printing the whole string. The leftmost "*" corresponds to -n 1. Specifying -n 0 causes match to print the whole matching string. Specifying -n -1 or using a value greater than the number of "*"s in the pattern causes match not to print anything, in which case you can still use the exit status to see if there is a match. The default value for n is 0, unless -g has also been specified, in which case the default is 1. -c command When -c is specified, match runs command with the system shell (/bin/sh), giving it as argument $0 the full string that matched, and as arguments $1, $2, etc., the parts of the string that matched any "*"s in pattern. If the command does not exit with status 0, match will exit immediately, before processing further matches, with whatever status command returned. The -c and -n flags are mutually exclusive. -p pattern Specifies the pattern to match against. The -p flag is optional; you can specify pattern as the first argument following the options. However, if you want to try matching the same input string against multiple patterns, then you must specify each pattern with a -p flag. -q This option is synonymous with -n -1; it suppresses output when there is a match. You can still determine whether a match occurred by the exit status. -r When a pattern matches the string in more than one way, the -r flag says to assign as much text as possible to the rightmost "*"s in the pattern. For example, with -r, pattern "*+*" would match text "a+b+c" with the "*" matching "a", and the second matching "b+c". -s Ordinarily, "*", "?", and negated character classes ("[!...]") do not match "/" characters. -s changes this behavior to match slashes. -x code By default, when there is no match, match exits with status 67. With this option, match exits with status code, instead. EXAMPLES
Suppose you have a directory with a bunch of files ending .c and .o. If, for each file named foo.c you want to attempt to delete the file foo.o, you can run the following command: match -p '*.c' -c 'rm -f $1.o' *.c Servers running the mailman list manager often send mail from bounce addresses of the form listname-bounces@host.com. If you subscribe to multiple lists on the same server, the mailman interface makes it easier if you subscribe under the same address. To split the mail into multiple folders based on the bounce address in the environment variable SENDER, you might chose a mailbox with the following shell code: name=`match -n1 "*-bounces@host.com" "$SENDER"` && echo "$HOME/Mail/incoming/host-$name.spool" SEE ALSO
avenger(1), avenger.local(8) The Mail Avenger home page: <http://www.mailavenger.org/>. AUTHOR
David Mazieres Mail Avenger 0.8.3 2012-04-05 match(1)
All times are GMT -4. The time now is 07:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy