Sponsored Content
Top Forums Shell Programming and Scripting Grep in file and print in the line Post 302861179 by justbow on Tuesday 8th of October 2013 10:15:47 AM
Old 10-08-2013
Grep in file and print in the line

hi

Code:
# cat test.txt
Test
Date: 20131008                 1515
--------------------------------------------------------------------------------------------------------------
Saxx = Proc_m0_s13                       : 1640
Saxx = Proc_m0_s15                       : 1791
Saxx = Proc_m0_s17                       : 1644
Saxx = Proc_m0_s19                       : 1599
Saxx = Proc_m0_s21                       : 1715
Saxx = Proc_m0_s23                       : 1686
Saxx = Proc_m1_s1                        : 1632
Saxx = Proc_m1_s3                        : 1712
Saxx = Proc_m1_s5                        : 1574
Saxx = _SYSTEM                           : 14993
Saxx = Proc_m0_s13                       : 1864
Saxx = Proc_m0_s15                       : 1766
Saxx = Proc_m0_s17                       : 1739
Saxx = Proc_m0_s19                       : 1845
Saxx = Proc_m0_s21                       : 1941
Saxx = Proc_m0_s23                       : 1841
Saxx = Proc_m1_s1                        : 1780
Saxx = Proc_m1_s3                        : 1810
Saxx = Proc_m1_s5                        : 1720
Saxx = _SYSTEM                           : 16306

i want the output become like this :

Code:
20131008 1515 SaxxProc_m0_s13 1640
20131008 1515 SaxxProc_m0_s15 1791
20131008 1515 SaxxProc_m0_s17 1644
20131008 1515 SaxxProc_m0_s19 1599
20131008 1515 SaxxProc_m0_s21 1715
20131008 1515 SaxxProc_m0_s23 1686
20131008 1515 SaxxProc_m1_s1 1632
20131008 1515 SaxxProc_m1_s3 1712
20131008 1515 SaxxProc_m1_s5 1574
20131008 1515 Saxx_SYSTEM 14993
20131008 1515 SaxxProc_m0_s13 1864
20131008 1515 SaxxProc_m0_s15 1766
20131008 1515 SaxxProc_m0_s17 1739
20131008 1515 SaxxProc_m0_s19 1845
20131008 1515 SaxxProc_m0_s21 1941
20131008 1515 SaxxProc_m0_s23 1841
20131008 1515 SaxxProc_m1_s1 1780
20131008 1515 SaxxProc_m1_s3 1810
20131008 1515 SaxxProc_m1_s5 1720
20131008 1515 Saxx_SYSTEM 16306

Anybody can help?
I have try :

Code:
ts=`cat test.txt  | grep Date | awk '{print $2' '$3}'`; cat test.txt | grep Saxx| awk '{print '$ts' " "$1$3" "$5}'

But not working
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

print a line containing word in a column using grep

hi, how to print a row which contains a perticular word in its third column using grep, cut, or any thing else. thanks (2 Replies)
Discussion started by: useless79
2 Replies

2. Shell Programming and Scripting

Awk+Grep Input file needs to match a column and print the entire line

I'm having problems since few days ago, and i'm not able to make it works with a simple awk+grep script (or other way to do this). For example, i have a input file1.txt: cat inputfile1.txt 218299910417 1172051195 1172070231 1172073514 1183135117 1183135118 1183135119 1281440202 ... (3 Replies)
Discussion started by: poliver
3 Replies

3. Shell Programming and Scripting

grep N lines after match and then print them on 1 line each

Hello I need some help with this job. file.txt ----- cut ---- TARGET 13/11/08 20:43:21 POINT 1 MOVE 8 772102y64312417771 TARGET 13/11/08 21:10:01 POINT 2 MOVE 5 731623jjd12njhd ----- cut ---- this is the example. i need to grep for the word TARGET and print next 4 lines like... (1 Reply)
Discussion started by: alekkz
1 Replies

4. UNIX for Dummies Questions & Answers

grep N lines after match and then print them on 1 line each

Hello I have a silly question. I need to grep a match in text file and then print 5 lines after it. grep -A 5 .... do it. OK The next thing I can not handle is I need each output to be on 1 line match line2 line3 line4 line5 match line2 line3 line4 line5 etc.. I will really... (10 Replies)
Discussion started by: alekkz
10 Replies

5. Shell Programming and Scripting

Find a string using grep & print the line above or below that.

Hi All, Please tell me how can I Find a string using grep & print the line above or below that in solaris? Please share as I am unable to use grep -A or grep -B as it is not working on Solaris. (10 Replies)
Discussion started by: Zaib
10 Replies

6. Shell Programming and Scripting

grep a string and print strings on that line

i have a file like below ABS 12234 A C 12G CFY 23865 A C 34D i want to grep "A C" then print ABS 12G 12234 CFY 34D 23865 Thanks! (4 Replies)
Discussion started by: kingpeejay
4 Replies

7. Shell Programming and Scripting

grep based on pattern in a line and print the column before that

$ cat file.log Message Number = : Sending message 10:50:16^|^reqhdr.dummyid^=^02^|^reqhdr.timezone^=^GMT+05:30^|^DUMMYREQUEST^=^BH||||||||||||||||||$BD|OL|C|V||DummyAcctNo|02||24/12/2011|ST_DDM|DDM||||||||reqUUID110612105016$BT||||||||||||||||||$] Length I have the above line in the... (4 Replies)
Discussion started by: kalidass
4 Replies

8. Shell Programming and Scripting

Grep or print each section of a file on one line with a separator

I can obtain information from itdt inventory command however it display as below, I'd like to print each entity on one line but seperated by : the file is something like and each section ends with Volume Tag Drive Address 256 Drive State ................... Normal ASC/ASCQ... (3 Replies)
Discussion started by: gefa
3 Replies

9. UNIX for Dummies Questions & Answers

Grep file and print value only if the following line doesnt contain value xxxx

Hi All, I have some large files which I would like to obtain some data from, I want to grep (or alturnative method) out certain values hut only if the folowing line doesnt contain a certain value. I will explain better below showing an example print of the data. NE : V0001 NE : V0002... (6 Replies)
Discussion started by: mutley2202
6 Replies

10. Shell Programming and Scripting

Grep echo awk print all output on one line

Hello, I've been trying to find the answer to this with Google and trying to browse the forums, but I haven't been able to come up with anything. If this has already been answered, please link me to the thread as I can't find it. I've been asked to write a script that pulls a list of our CPE... (51 Replies)
Discussion started by: rwalker
51 Replies
POE::Filter::Grep(3pm)					User Contributed Perl Documentation				    POE::Filter::Grep(3pm)

NAME
POE::Filter::Grep - select or remove items based on simple rules SYNOPSIS
#!perl use POE qw( Wheel::FollowTail Filter::Line Filter::Grep Filter::Stackable ); POE::Session->create( inline_states => { _start => sub { my $parse_input_as_lines = POE::Filter::Line->new(); my $select_sudo_log_lines = POE::Filter::Grep->new( Put => sub { 1 }, Get => sub { my $input = shift; return $input =~ /sudo[d+]/i; }, ); my $filter_stack = POE::Filter::Stackable->new( Filters => [ $parse_input_as_lines, # first on get, last on put $select_sudo_log_lines, # first on put, last on get ] ); $_[HEAP]{tailor} = POE::Wheel::FollowTail->new( Filename => "/var/log/system.log", InputEvent => "got_log_line", Filter => $filter_stack, ); }, got_log_line => sub { print "Log: $_[ARG0] "; } } ); POE::Kernel->run(); exit; DESCRIPTION
POE::Filter::Grep selects or removes items based on simple tests. It may be used to filter input, output, or both. This filter is named and modeled after Perl's built-in grep() function. POE::Filter::Grep is designed to be combined with other filters through POE::Filter::Stackable. In the "SYNOPSIS" example, a filter stack is created to parse logs as lines and remove all entries that don't pertain to a sudo process. (Or if your glass is half full, the stack only selects entries that DO mention sudo.) PUBLIC FILTER METHODS
In addition to the usual POE::Filter methods, POE::Filter::Grep also supports the following. new new() constructs a new POE::Filter::Grep object. It must either be called with a single Code parameter, or both a Put and a Get parameter. The values for Code, Put, and Get are code references that, when invoked, return true to select an item or false to reject it. A Code function will be used for both input and output, while Get and Put functions allow input and output to be filtered in different ways. The item in question will be passed as the function's sole parameter. sub reject_bidoofs { my $pokemon = shift; return 1 if $pokemon ne "bidoof"; return; } my $gotta_catch_nearly_all = POE::Filter::Grep->new( Code => &reject_bidoofs, ); Enforce read-only behavior: my $read_only = POE::Filter::Grep->new( Get => sub { 1 }, Put => sub { 0 }, ); modify modify() changes a POE::Filter::Grep object's behavior at run-time. It accepts the same parameters as new(), and it replaces the existing tests with new ones. # Don't give away our Dialgas. $gotta_catch_nearly_all->modify( Get => sub { 1 }, Put => sub { return shift() ne "dialga" }, ); SEE ALSO
POE::Filter for more information about filters in general. POE::Filter::Stackable for more details on stacking filters. BUGS
None known. AUTHORS &; COPYRIGHTS The Grep filter was contributed by Dieter Pearcey. Documentation is provided by Rocco Caputo. Please see the POE manpage for more information about authors and contributors. perl v5.14.2 2012-05-15 POE::Filter::Grep(3pm)
All times are GMT -4. The time now is 11:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy