Grep syntax print after certain character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep syntax print after certain character
# 1  
Old 08-17-2011
Grep syntax print after certain character

My current code is:
Code:
user@ubuntu:~/Desktop$ grep -e "\(packaged by\)\|\(employee\)\|\(file name\)\|\(Total Data (MB) Read\)\|\(Begin Time\)" log.txt
     packaged by = Ron Mexico
     employee = Michael Vick
     file name = Mike_Vick_2011.bat
Total Data (MB) Read: 11.82
Begin Time: 6/13/2011 10:29:27 AM

How can I get the output to be:
Code:
Ron Mexico
Michael Vick
Mike_Vick_2011.bat
11.82
6/13/2011 10:29:27 AM

# 2  
Old 08-17-2011
Code:
$ grep -e "\(packaged by\)\|\(employee\)\|\(file name\)\|\(Total Data (MB) Read\)\|\(Begin Time\)" log.txt|awk -F"=" '{print $2}'

This User Gave Thanks to dude2cool For This Post:
# 3  
Old 08-17-2011
Code:
awk -F"=" '{print $2}'

This works, but I also have ":" in the logs. Any way to combine "=" and ":"?

Thanks for the quick response.
# 4  
Old 08-17-2011
use it like

Code:
awk -F"[:=]" '{print $2}'

This User Gave Thanks to itkamaraj For This Post:
# 5  
Old 08-17-2011
The date stamp gets jacked up because it removes the ":" in the time.

Code:
6/13/2011 10

Is it possible to do something like:
Code:
awk -F"[:=]" '{print $2,":",print $3,":",print $4}'

# 6  
Old 08-17-2011
Please post the input data and the required output.
# 7  
Old 08-17-2011
Code:
user@ubuntu:~/Desktop$ grep -e "\(packaged by\)\|\(employee\)\|\(file name\)\|\(Total Data (MB) Read\)\|\(Begin Time\)" log.txt
     packaged by = Ron Mexico
     employee = Michael Vick
     file name = Mike_Vick_2011.bat
Total Data (MB) Read: 11.82
Begin Time: 6/13/2011 10:29:27 AM

Output should be:
Code:
Ron Mexico
Michael Vick
Mike_Vick_2011.bat
11.82
6/13/2011 10:29:27 AM

If you have the time, I'm really trying to get the output into a CSV, so the output should be:
Code:
"Ron Mexico","Michael Vick","Mike_Vick_2011.bat","11.82","6/13/2011 10:29:27 AM"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

FIND and GREP syntax

I have a question to this command find . -type f -name ".*txt" -exec grep "text" {}\. The find command will locate a file name with the extension of txt once per round and find the word "text" in the content of the file or the find command will locate all the file names with the extension of... (2 Replies)
Discussion started by: TestKing
2 Replies

2. Shell Programming and Scripting

Help on grep syntax in UNIX

Dear Team /app/Appln/logs/ echo Session used server are 'grep -i pid|grep -i session | cut -d'.' -f1 | awk '{print $9}' | sort | uniq' Output - lxserver01 lxserver02 lxserver03 When I grep session pid in logs server details I can see above distinct server details but I... (6 Replies)
Discussion started by: skp
6 Replies

3. Shell Programming and Scripting

problem with print append to output file syntax

I'm trying to output the contents of the infile to the outfile using Append. I will want to use append but the syntax doesn't seem to be working ! Input file (called a.txt) contains this: a a a b b b I'm running shell script (called k.sh) from Unix command-line like this: ./k.sh .... (1 Reply)
Discussion started by: script_op2a
1 Replies

4. Shell Programming and Scripting

read the text file and print the content character by character..

hello all i request you to give the solution for the following problem.. I want read the text file.and print the contents character by character..like if the text file contains google means..i want to print g go goo goog googl google like this Using unix Shell scripting... without using... (1 Reply)
Discussion started by: samupnl
1 Replies

5. UNIX for Dummies Questions & Answers

| help | unix | grep (GNU grep) 2.5.1 | advanced regex syntax

Hello, I'm working on unix with grep (GNU grep) 2.5.1. I'm going through some of the newer regex syntax using Regular Expression Reference - Advanced Syntax a guide. ls -aLl /bin | grep "\(x\)" Which works, just highlights 'x' where ever, when ever. I'm trying to to get (?:) to work but... (4 Replies)
Discussion started by: MykC
4 Replies

6. Shell Programming and Scripting

Sed syntax to print lines that do not end with )}

I must admit I am relativly new to sed, and I am trying to make a simple sed query to search log files and return multiple variables from multiple logs. So far I have had success, but one problem remains: Alot of lines in the log files wrap onto multiple lines and are not being returned as... (2 Replies)
Discussion started by: demanche
2 Replies

7. Shell Programming and Scripting

Perl Script Syntax to Extract Everything After Special Character

Hi, I am writing a Perl script that reads in many lines, if a line meets the criteria I want to edit, it. For example, the script will return the following example line... test=abc123 All I want to do is strip off the "test=" and just be left with the abc123. In my script I can easily... (3 Replies)
Discussion started by: edrichard
3 Replies

8. Shell Programming and Scripting

MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else

Hi Guys, I need to set the value of $7 to zero in case $7 is NULL. I've tried the below command but doesn't work. Any ideas. thanks guys. MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else { print $7}}' ` Harby. (4 Replies)
Discussion started by: hariza
4 Replies

9. Shell Programming and Scripting

grep syntax for this...

I wanna grep for a pattern logs 1 2 & 3 within a folder containing 100 logs grep "test" /folder/log1 /folder/log2 /folder/log3 The above command will work fine but is there any command like grep "test" /folder/log1, log2, log3 or something similar (4 Replies)
Discussion started by: roshanjain2
4 Replies

10. Shell Programming and Scripting

Need help with the syntax using awk+grep

Hi, I need to extract information from a 4 GB file based on the following conditions: 1) Check for the presence of a set of account numbers Each account number is present along with other information within a PAGESTART and PAGEEND. The file looks like this: PAGESTART ACCOUNT NO 123... (6 Replies)
Discussion started by: kthri
6 Replies
Login or Register to Ask a Question