Grep syntax print after certain character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep syntax print after certain character
# 8  
Old 08-17-2011
Code:
$ awk -F"[:=]" '{if($0~/Time/){printf("\"%s:%s:%s\"\n",$2,$3,$4)}else{printf("\"%s\",",$2)}}' test.txt 
" Ron Mexico"," Michael Vick"," Mike_Vick_2011.bat"," 11.82"," 6/13/2011 10:29:27 AM"

---------- Post updated at 08:39 PM ---------- Previous update was at 08:31 PM ----------

you dont need to use grep and pipe this awk. You can try the below.

Code:
awk -F"[:=]" ' /packaged by/ || /employee/ || /file name/ || /Total Data/|| /Begin Time/ {if($0~/Time/){printf("\"%s:%s:%s\"\n",$2,$3,$4)}else{printf("\"%s\",",$2)}}' log.txt

# 9  
Old 08-17-2011
How do you remove the space after any "="?

Something like?
Code:
awk -F"[':' '= ']"

---------- Post updated at 01:42 PM ---------- Previous update was at 01:21 PM ----------

Is this going to work for all files in a directory?

This will parse the first file, but not work on other log files in the directory:
Code:
awk -F"[:=]" ' /packaged by/ || /employee/ || /file name/ || /Total Data/|| /Begin Time/ {if($0~/Time/){printf("\"%s:%s:%s\"\n",$2,$3,$4)}else{printf("\"%s\",",$2)}}' /path/to/*

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