Print all lines after a string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print all lines after a string
# 1  
Old 07-28-2014
Print all lines after a string

My file has the following contents...

Code:
User:SYS,O/SUser:oracle,Process:10813484,Machine:host123.xxx.xxx.xxxxxxx.com.au,Program:sqlplus@host123.xxx.xxx.xxxxxxx.com.au(TNSV1-V,LogonTime:24-JUL-2014 
15:04

I would like to print all character appearing after the string LogonTime:

My output shoud be...
Code:
24-JUL-2014 15:04

Thanks

Last edited by Don Cragun; 07-28-2014 at 10:07 PM.. Reason: Add CODE tags.
# 2  
Old 07-28-2014
Please use [code] and [/code] tags around any data or programs.

Try this:

Code:
sed 's/^.*LogonTime://' infile

# 3  
Old 07-28-2014
The query gives me the following output...

Code:
sed 's/^.*LogonTime:*//' sample.log

Code:
User:SYS,O/SUser:oracle,Process:10813484,Machine:host123.xxx.xxx.xxxxxxx.com.au
24-JUL-2014
15:04


Last edited by Nagesh_1985; 07-29-2014 at 01:24 AM..
# 4  
Old 07-29-2014
Code:
sed 's/.*LogonTime:\(.*\)/\1/' file

Code:
awk -F 'LogonTime:' 'NF>1{print $2}' file

# 5  
Old 07-29-2014
Or try:
Code:
awk -F"LogonTime:" '{print $2}' infile


# 6  
Old 07-29-2014
If you would have used CODE tags as required by forum rules, people who looked at your post (before it was edited by an administrator), might have realized that your sample input was two lines instead of one, and might have known that the 1st line in your sample input ended with a space character just before the newline line terminator.

This seems to do what you have requested:
Code:
awk '
f {	printf("%s", $0)
	next
}
{	if(f = sub(/.*LogonTime:/, ""))
		printf("%s", $0)
}
END {	if(f)
		print ""
}' file

This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find a string and print all lines upto another string

Ok I would like to do the following file test contains the following lines. between the lines ABC there may be any amount of lines up to the next ABC entry. I want to grep for the filename.txt entry and print the lines in between (and including that line) up to and including the last line... (3 Replies)
Discussion started by: revaroo
3 Replies

2. Shell Programming and Scripting

Grep for the string and then print the next 4 lines

RHEL 5.8 I have a text file like below. I want to grep for a string and then print the next 4 lines including the line with the string I grepped for For eg: I want grep for the string HANS and then print the next 4 lines including HANS $ cat someText.txt JOHN NATIONALITY:... (7 Replies)
Discussion started by: omega3
7 Replies

3. Shell Programming and Scripting

How to print the lines in a file for the given string?

Hi, I have a file with contents test id text day test sah dh dhs yeay fg jsh jsjk my need: I give a string as a input, it check the file and display the lines with the given string e.g input : test output: test id text day test sah dh dhs (1 Reply)
Discussion started by: nanthagopal
1 Replies

4. Shell Programming and Scripting

Print lines that match regex on xth string

Hello, I need an awk command to print only the lines that match regex on xth field from file. For example if I use this command awk -F"|" ' $22 == "20130117090000.*" 'It wont work, I think, because single quotes wont allow the usage of the metacharacter star * . On the other hand I dont know... (2 Replies)
Discussion started by: black_fender
2 Replies

5. Shell Programming and Scripting

Search string and print the above line and below lines?.

if the first string matches then print the previous line and current line and also print the following lines if the other string search matches. Input ------ TranTime 2012 10 12 The Record starts here Accountnumber: 4632473431274 TxnCode 323 TranID 329473242834 ccsdkcnsdncskd... (7 Replies)
Discussion started by: laknar
7 Replies

6. Shell Programming and Scripting

Print lines between two lines after grep for a text string

I have several very large file that are extracts from Oracle tables. These files are formatted in XML type syntax with multiple entries like: <ROW> some information more information </ROW> I want to grep for some words, then print all lines between <ROW> AND </ROW>. Can this be done with AWK?... (7 Replies)
Discussion started by: jbruce
7 Replies

7. Shell Programming and Scripting

Print #of lines after search string in a big file

I have a command which prints #lines after and before the search string in the huge file nawk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r;print;c=a}b{r=$0}' b=0 a=10 s="STRING1" FILE The file is 5 gig big. It works great and prints 10 lines after the lines which contains search string in... (8 Replies)
Discussion started by: prash184u
8 Replies

8. Shell Programming and Scripting

print string at the end of lines in text file

hello, I go text file like this E:/DDD/Dyndede/wwww E:/DDD/sss.com/ffffg/fff E:/DDD/vvvvvv/dd E:/DDD/sss.com/bbbbbb E:/DDD/sss.com/nnnn/xxI want to print /alpha.jpg at the end of every lines like that E:/DDD/Dyndede/wwww/alpha.jpg E:/DDD/sss.com/ffffg/fff/alpha.jpg... (8 Replies)
Discussion started by: davidkhan
8 Replies

9. Shell Programming and Scripting

Need help to print lines contains particular string format in a file

Hi, I want to print the lines in a file that matches particular string format using shell scripting. (4 Replies)
Discussion started by: sudhakaryadav
4 Replies

10. Shell Programming and Scripting

print only matched string instead lines in grep

frnd, Is there any way to print only the string that matched the pattern instead printing the whole line? thanks in advance. (3 Replies)
Discussion started by: clx
3 Replies
Login or Register to Ask a Question