Print all the words after a match word


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print all the words after a match word
# 1  
Old 05-15-2010
Print all the words after a match word

Hi,

I want to print all words till the last word after the match of "ERROR" word. For e.g.

I'll get an sqlplus error with
e.g. 1
Code:
 
$ ./calltest_fn.ksh
var test_var:=test_fn1; calltest_fn.ksh file1 file2 file3 ERROR at line 4: ORA-06550: line 4, column 11: PLS-00201: identifier 'test_fn1' must be declared ORA-06550: line 4, column 1: PL/SQL: Statement ignored

Now I want to print all the words after "ERROR" word. i.e. the output should be:
Code:
 
ERROR at line 4: ORA-06550: line 4, column 11: PLS-00201: identifier 'test_fn1' must be declared ORA-06550: line 4, column 1: PL/SQL: Statement ignored

Also e.g. 1 is one line only not separate lines; I know that we can print lines matching regEx with sed but don't how to print words?

-dips
# 2  
Old 05-15-2010
try this..
Code:
sed 's/\(.*\)\(ERROR.*\)/\2/g' filename

# 3  
Old 05-15-2010
Code:
sed "s/.*ERROR/ERROR/"

# 4  
Old 05-15-2010
Code:
sed 's/^var.*\(ERROR.*\)$/\1/' error

# 5  
Old 05-15-2010
If the word "ERROR" can itself appear in the error message, then the greedy nature of all the preceding solutions will only return part of the message. It may very well be that this is unlikely and of no concern. But, if it is, the following alternatives behave properly under such circumstances (the sh solution assumes that the error message is stored in e):
Code:
[ -z "${e##*ERROR*}" ] && echo "ERROR${e#*ERROR}"

Code:
sed 's/ERROR.*/&&/; s/.*\(ERROR.*\)\1/\1/'

Code:
awk 'i=index($0, "ERROR") {print substr($0, i)}'

Code:
perl -lne 'print $1 if /.*?(ERROR.*)$/'

Regards,
Alister

Last edited by alister; 05-15-2010 at 10:00 PM..
# 6  
Old 05-15-2010
All good and well, but it's an Oracle error, and that being superiorly efficient never feels the need to print the word ERROR more than once Smilie

But just to be sure:
Code:
sed "s/.*ERROR at line/ERROR at line/"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to print the next word from the same line based on grep string condtion match.

I need to fetch particular string from log file based on grep condition match. Actual requirement is need to print the next word from the same line based on grep string condtion match. File :Java.lanag.xyz......File copied completed : abc.txt Ouput :abc.txt I have used below... (5 Replies)
Discussion started by: siva83
5 Replies

2. Shell Programming and Scripting

Gawk gensub, match capital words and lowercase words

Hi I have strings like these : Vengeance mitt Men Vengeance gloves Women Quatro Windstopper Etip gloves Quatro Windstopper Etip gloves Girls Thermobite hooded jacket Thermobite Triclimate snow jacket Boys Thermobite Triclimate snow jacket and I would like to get the lower case words at... (2 Replies)
Discussion started by: louisJ
2 Replies

3. Shell Programming and Scripting

How to match the first word and print only that line in UNIX?

Below is the file DISK-A 109063.2 49 31 40.79 DISK-B 110058.5 49 44 57.07 DISK-c 4402.4 2 1 2.14 from the file, i want to search for 'DISK-A' and print only that line with the first word matching to DISK-A and the output should skip DISK-A. Desired Output: (If i'm... (2 Replies)
Discussion started by: web2moha
2 Replies

4. Shell Programming and Scripting

Print string after the word match

Hi, I have the logs : cat logsx.txt 744906,{"reportingGroups":,"version":"2.0"} 678874,{"reportingGroups":,"version":"2.0"} 193571,{"reportingGroups":,"version":"2.0"} 811537,{"reportingGroups":,"version":"2.0"} 772024,{"reportingGroups":,"version":"2.0"}... (5 Replies)
Discussion started by: justbow
5 Replies

5. Shell Programming and Scripting

Print a word after a match

Hi all, I have the below line: 08 03 * * 1-5 XXXXXXXXXXXXX -ENVI LDNFOUAT10 -EXE xxxxxxxx -CONFIG \${xxxxx} -SUBCLASS RESET -START -EXTRAAPPARGS \" -env 38LDNFOUAT10 \" >> /tmp/SRRC_xxxxxxx_start.log.`/usr/bin/date +\%Y\%m\%d` 2>&1 I want to print just one word after the string "-env", in... (7 Replies)
Discussion started by: Cvg
7 Replies

6. Shell Programming and Scripting

Match the word or words and fetch the entries

Hi all, I have 7 words Now I have 1 file which contain data in large number of rows and columns and 6th column contain any of these words or may be more than one words among above 7 words: I want script should search for the above mentioned 7 words in the 6th column ... (9 Replies)
Discussion started by: manigrover
9 Replies

7. Shell Programming and Scripting

match sentence and word adn fetch similar words in alist

Hi all, I have ot match sentence list and word list anf fetch similar words in a separate file second file with 2 columns So I want the output shuld be 2 columns like this (3 Replies)
Discussion started by: manigrover
3 Replies

8. Shell Programming and Scripting

find a word and print n lines before and after the match

how to find a word and print n lines before and after the match until a blank line is encounterd (14 Replies)
Discussion started by: chidori
14 Replies

9. Shell Programming and Scripting

print word after pattern match in two instances

i have a file like below. how can i printout the digits followed by the pattern -bwout and -bwin. say i run the script by entering line number 145 (the fourth line), then the o/p should be like 5000000 1024000 8 test1 -ipprot erp -ppsout 500 -ppsin 500 -bwout 300000 -bwin 300000 -statsdevice... (7 Replies)
Discussion started by: sb245
7 Replies

10. Shell Programming and Scripting

Search word in a line and print earlier pattern match

Hi All, I have almost 1000+ files and I want to search specific pattern. Looking forwarded your input. Search for: word1.word2 (Which procedure contain this word, I need procedure name in output. Expected output: procedure test1 procedure test2 procedure test3 procedure test4 ... (7 Replies)
Discussion started by: susau_79
7 Replies
Login or Register to Ask a Question