Sponsored Content
Top Forums Shell Programming and Scripting Perl print between 2 patterns Post 302533631 by killer54291 on Friday 24th of June 2011 09:30:48 AM
Old 06-24-2011
2 things - I wouldn't know how to go about including that in ONLY A PERL SCRIPT and the input is a variable, not a file.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search for the two patterns and print everything in between

Hi all, I have a file having data: @HWUSI-EAS1727:19:6:1:3674:984:0:1#GTTAATA NTTGGGTTTTCT @HWUSI-EAS1727:19:6:1:3674:984:0:1#GTTA... NTTGGGTTTTCT @HWUSI-EAS1727:19:6:1:3674:984:0:1#.....CT NTTGGGTTTTCT I want to print everything starting from # till line ends. can you please help me how... (5 Replies)
Discussion started by: pirates.genome
5 Replies

2. Shell Programming and Scripting

print all between patterns with special chars

Hi, I'm having trouble with awk print all characters between 2 patterns. I tried more then one solution found on this forum but with no success. Probably my mistakes are due to the special characters "" and "]"in the search patterns. Well, have a log file like this: logfile.txt ... (3 Replies)
Discussion started by: ginolatino
3 Replies

3. Shell Programming and Scripting

To print certain patterns in a column

Hi, From my input files, I want to print $1, $2 and only certain pattern in $4 (EC). I use this code but it print all the words in $4 awk -F"\t" '$4 {print $1,$2,$4}I just want EC follows by the numbers in $4 The input file as follows:- Entry Entry name Status Names Q01284 ... (7 Replies)
Discussion started by: redse171
7 Replies

4. Shell Programming and Scripting

Need to print between patterns AND a few lines before

I need to print out sections (varying numbers of lines) of a file between patterns. That alone is easy enough: sed -n '/START/,/STOP/' I also need the 3 lines BEFORE the start pattern. That alone is easy enough: grep -B3 START But I can't seem to combine the two so that I get everything between the... (2 Replies)
Discussion started by: Finja
2 Replies

5. Shell Programming and Scripting

How to print only lines in between patterns?

Hi, I want to print only lines (green-italic lines) in between first and last strings in column 9. there are different number of lines between each strings. 10 AUGUSTUS exon 4558 4669 . - . 10.g1 10 AUGUSTUS exon 8771 8889 . ... (6 Replies)
Discussion started by: jamo
6 Replies

6. Shell Programming and Scripting

Print all lines between patterns

Hi Gurus, I have a requirement where I need to display all lines between 2 patterns except the line where the first pattern in it. I tried the following command using awk but it is printing all lines except the lines where the 2 patterns exist. awk '/TRANSF_/{ P=1; next } /Busy/ {exit} P'... (9 Replies)
Discussion started by: svajhala
9 Replies

7. Shell Programming and Scripting

Perl : to print the lines between two patterns

Hello experts, I have a text file from which I need to print all the lines between the patterns. Could anyone please help me with the perl script. names.txt ========= Badger Bald Eagle Bandicoot Bangle Tiger Barnacle Barracuda Basilisk Bass Basset Hound Beetle Beluga... (7 Replies)
Discussion started by: scriptscript
7 Replies

8. Shell Programming and Scripting

Print between multiple patterns

Hello Gurus, I have a file this Dir Path 1 Connection pool="somename"; "DataSource Name"="DS name"; Password="pwd"; User Id="uid";some other fields Dir Path2 Password="pwd2"; User id="uid2"; Connection pool="somename2"; "datasource name"="DS name2";some other fields. Under each dir... (14 Replies)
Discussion started by: sirababu
14 Replies

9. Shell Programming and Scripting

Find matched patterns and print them with other patterns not the whole line

Hi, I am trying to extract some patterns from a line. The input file is space delimited and i could not use column to get value after "IN" or "OUT" patterns as there could be multiple white spaces before the next digits that i need to print in the output file . I need to print 3 patterns in a... (3 Replies)
Discussion started by: redse171
3 Replies

10. Shell Programming and Scripting

How to print different multiple lines after two patterns?

Hello, I need to print some lines as explained below, TXT example 1111 2222 3333 4444 5555 6666 7777 8888 6666 9999 1111 2222 3333 4444 5555 (8 Replies)
Discussion started by: liuzhencc
8 Replies
PERF_3.2-SCRIPT-PERL(1) 					    perf Manual 					   PERF_3.2-SCRIPT-PERL(1)

NAME
perf-script-perl - Process trace data with a Perl script SYNOPSIS
perf script [-s [Perl]:script[.pl] ] DESCRIPTION
This perf script option is used to process perf script data using perf's built-in Perl interpreter. It reads and processes the input file and displays the results of the trace analysis implemented in the given Perl script, if any. STARTER SCRIPTS
You can avoid reading the rest of this document by running perf script -g perl in the same directory as an existing perf.data trace file. That will generate a starter script containing a handler for each of the event types in the trace file; it simply prints every available field for each event in the trace file. You can also look at the existing scripts in ~/libexec/perf-core/scripts/perl for typical examples showing how to do basic things like aggregate event data, print results, etc. Also, the check-perf-script.pl script, while not interesting for its results, attempts to exercise all of the main scripting features. EVENT HANDLERS
When perf script is invoked using a trace script, a user-defined handler function is called for each event in the trace. If there's no handler function defined for a given event type, the event is ignored (or passed to a trace_handled function, see below) and the next event is processed. Most of the event's field values are passed as arguments to the handler function; some of the less common ones aren't - those are available as calls back into the perf executable (see below). As an example, the following perf record command can be used to record all sched_wakeup events in the system: # perf record -a -e sched:sched_wakeup Traces meant to be processed using a script should be recorded with the above option: -a to enable system-wide collection. The format file for the sched_wakep event defines the following fields (see /sys/kernel/debug/tracing/events/sched/sched_wakeup/format): .ft C format: field:unsigned short common_type; field:unsigned char common_flags; field:unsigned char common_preempt_count; field:int common_pid; field:char comm[TASK_COMM_LEN]; field:pid_t pid; field:int prio; field:int success; field:int target_cpu; .ft The handler function for this event would be defined as: .ft C sub sched::sched_wakeup { my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs, $common_pid, $common_comm, $comm, $pid, $prio, $success, $target_cpu) = @_; } .ft The handler function takes the form subsystem::event_name. The $common_* arguments in the handler's argument list are the set of arguments passed to all event handlers; some of the fields correspond to the common_* fields in the format file, but some are synthesized, and some of the common_* fields aren't common enough to to be passed to every event as arguments but are available as library functions. Here's a brief description of each of the invariant event args: $event_name the name of the event as text $context an opaque 'cookie' used in calls back into perf $common_cpu the cpu the event occurred on $common_secs the secs portion of the event timestamp $common_nsecs the nsecs portion of the event timestamp $common_pid the pid of the current task $common_comm the name of the current process All of the remaining fields in the event's format file have counterparts as handler function arguments of the same name, as can be seen in the example above. The above provides the basics needed to directly access every field of every event in a trace, which covers 90% of what you need to know to write a useful trace script. The sections below cover the rest. SCRIPT LAYOUT
Every perf script Perl script should start by setting up a Perl module search path and 'use'ing a few support modules (see module descriptions below): .ft C use lib "$ENV{'PERF_EXEC_PATH'}/scripts/perl/perf-script-Util/lib"; use lib "./perf-script-Util/lib"; use Perf::Trace::Core; use Perf::Trace::Context; use Perf::Trace::Util; .ft The rest of the script can contain handler functions and support functions in any order. Aside from the event handler functions discussed above, every script can implement a set of optional functions: trace_begin, if defined, is called before any event is processed and gives scripts a chance to do setup tasks: .ft C sub trace_begin { } .ft trace_end, if defined, is called after all events have been processed and gives scripts a chance to do end-of-script tasks, such as display results: .ft C sub trace_end { } .ft trace_unhandled, if defined, is called after for any event that doesn't have a handler explicitly defined for it. The standard set of common arguments are passed into it: .ft C sub trace_unhandled { my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs, $common_pid, $common_comm) = @_; } .ft The remaining sections provide descriptions of each of the available built-in perf script Perl modules and their associated functions. AVAILABLE MODULES AND FUNCTIONS
The following sections describe the functions and variables available via the various Perf::Trace::* Perl modules. To use the functions and variables from the given module, add the corresponding use Perf::Trace::XXX line to your perf script script. Perf::Trace::Core Module These functions provide some essential functions to user scripts. The flag_str and symbol_str functions provide human-readable strings for flag and symbolic fields. These correspond to the strings and values parsed from the print fmt fields of the event format files: flag_str($event_name, $field_name, $field_value) - returns the string represention corresponding to $field_value for the flag field $field_name of event $event_name symbol_str($event_name, $field_name, $field_value) - returns the string represention corresponding to $field_value for the symbolic field $field_name of event $event_name Perf::Trace::Context Module Some of the common fields in the event format file aren't all that common, but need to be made accessible to user scripts nonetheless. Perf::Trace::Context defines a set of functions that can be used to access this data in the context of the current event. Each of these functions expects a $context variable, which is the same as the $context variable passed into every event handler as the second argument. common_pc($context) - returns common_preempt count for the current event common_flags($context) - returns common_flags for the current event common_lock_depth($context) - returns common_lock_depth for the current event Perf::Trace::Util Module Various utility functions for use with perf script: nsecs($secs, $nsecs) - returns total nsecs given secs/nsecs pair nsecs_secs($nsecs) - returns whole secs portion given nsecs nsecs_nsecs($nsecs) - returns nsecs remainder given nsecs nsecs_str($nsecs) - returns printable string in the form secs.nsecs avg($total, $n) - returns average given a sum and a total number of values SEE ALSO
perf_3.2-script(1) perf 06/24/2012 PERF_3.2-SCRIPT-PERL(1)
All times are GMT -4. The time now is 07:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy