Sponsored Content
Full Discussion: awk bash help
Top Forums Shell Programming and Scripting awk bash help Post 302314583 by a-gopal on Friday 8th of May 2009 06:48:13 PM
Old 05-08-2009
awk bash help

Hi,
I'm trying to read a file containing lines with spaces in them.

The inputfile looks like this
------------------------------
Command1 arg1 arg2
Command2 arg5 arg6 arg7
-------------------------------

The shell code looks like this...

lines=`awk '{ print }' inputfile`

for LINE in $lines ; do
echo ${LINE}
done

output is
--------------------
Command1
arg1
arg2
Command2
arg5
arg6
arg7
--------------------

What I really want is
--------------------
Command1 arg1 arg2
Command2 arg5 arg6 arg7


How do I do it..

TIA.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

BASH with AWK

Hello, I have a file.txt with 20000 lines and 2 columns each which consists of current_filename and new_filename . I want to create a script to find files in a directory with current_filename and move it to new folder with new_filename. Could you please help me how to do that?? ... (2 Replies)
Discussion started by: narasimhulu
2 Replies

2. Shell Programming and Scripting

Is there any better way for sorting in bash/awk

Hi, I have a file which is:- 1 6 4 8 2 3 2 1 9 3 2 1 3 3 5 6 3 1 4 9 7 8 2 3 I would like to sort from field $2 to field $6 for each of the line to:- 1 2 3 4 6 8 2 1 1 2 3 9 3 1 3 3 5 6 4 2 3 7 8 9 I came across this Arrays on example 26-6. But it is much complicated. I am... (7 Replies)
Discussion started by: ahjiefreak
7 Replies

3. Shell Programming and Scripting

scripting help with bash and awk

I'm trying to reformat some tide information into a useable format and failing. Input file is.... 4452 CHENNAI (MADRAS) 13°06'N, 80°18'E India East Coast 01 June 2009 UT(GMT) Data Area 3. Indian Ocean (northern part) and Red Sea to Singapore 01/06/2009 00:00 0.7 m 00:20 0.7 m 00:40... (3 Replies)
Discussion started by: garethsays
3 Replies

4. UNIX for Dummies Questions & Answers

Help with BASH/AWK queries ....

Hi Everyone, I have an input file in the following format: score.file1.txt contig00045 length=566 numreads=19 1047 0.0 contig00055 length=524 numreads=7 793 0.0 contig00052 length=535 numreads=10 607 e-176 contig00072 length=472 numreads=46 571 e-165... (8 Replies)
Discussion started by: Fahmida
8 Replies

5. Shell Programming and Scripting

AWK/Bash script

I would like to write a script to extend this command to a general case: BEGIN {s_0=0;n_0=0}{n_0++;s_0+=($51-$1)^2}END {print sqrt(s_0/n_0)} i.e. so that BEGIN {s_0=0;n_0=0}{n_0++;s_0+=($51-$1)^2}END {print sqrt(s_0/n_0)} BEGIN {s_1=0;n_1=0}{n_1++;s_1+=($51-$2)^2}END {print... (3 Replies)
Discussion started by: chrisjorg
3 Replies

6. UNIX for Dummies Questions & Answers

Help in awk/bash

Hi, I am also a newbie in awk and trying to find solution of my problem. I have one reference file 1.txt with 2 columns and I want to search other 10 files (a.txt, b.txt......h.txt each with 5 columns) corresponding to the values of 2nd column from 1.txt. If the value from 2nd column from 1.txt... (0 Replies)
Discussion started by: bioinfo
0 Replies

7. Shell Programming and Scripting

Help in awk/bash

Hi, I have two files: atom.txt and g.txt atom.txt has multiple patterns but I am showing only two patterns each ending with ENDMDL: ATOM 1 N SER A 1 35.092 83.194 140.076 1.00 0.00 N ATOM 2 CA SER A 1 35.216 83.725 138.725 1.00 0.00 C TER ENDMDL ATOM 1 N SER A 1 35.683 81.326 139.778 1.00... (11 Replies)
Discussion started by: bioinfo
11 Replies

8. Shell Programming and Scripting

Help in awk/bash

Hi, I am also a newbie in awk and trying to find solution of my problem. I have one reference file 1.txt with 2 columns and I want to search other 10 files (a.txt, b.txt......h.txt each with 5 columns) corresponding to the values of 2nd column from 1.txt. If the value from 2nd column from 1.txt... (33 Replies)
Discussion started by: bioinfo
33 Replies

9. Shell Programming and Scripting

Returning a value from awk to bash

Hi I am a newbie starting bash and I have a simple need to return the result of an operation from awk to bash. basically I want to use awk to tell me if "#" exists in a string, and then back in bash, i want to do an IF statement on this return in order to do other things. In my bash shell I... (2 Replies)
Discussion started by: oahmad
2 Replies

10. UNIX for Dummies Questions & Answers

New problem with awk using bash

Hi! I have a new problem with awk, this time I think is because I'm using it in bash and I don't know how to put the valor of the variable in awk. Here is the code: #!/bin/bash for i in 1 2 3 4 5 do a=$i b=$ awk '$1>=a&&$1<=b {print $1,$2,$3}'>asdf test... (3 Replies)
Discussion started by: florpi
3 Replies
SDT(9)							   BSD Kernel Developer's Manual						    SDT(9)

NAME
SDT -- a DTrace framework for adding statically-defined tracing probes SYNOPSIS
#include <sys/param.h> #include <sys/queue.h> #include <sys/sdt.h> SDT_PROVIDER_DECLARE(prov); SDT_PROVIDER_DEFINE(prov); SDT_PROBE_DECLARE(prov, mod, func, name); SDT_PROBE_DEFINE(prov, mod, func, name); SDT_PROBE_DEFINE0(prov, mod, func, name); SDT_PROBE_DEFINE1(prov, mod, func, name, arg0); SDT_PROBE_DEFINE2(prov, mod, func, name, arg0, arg1); SDT_PROBE_DEFINE3(prov, mod, func, name, arg0, arg1, arg2); SDT_PROBE_DEFINE4(prov, mod, func, name, arg0, arg1, arg2, arg3); SDT_PROBE_DEFINE5(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4); SDT_PROBE_DEFINE6(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4, arg5); SDT_PROBE_DEFINE7(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4, arg5, arg6); SDT_PROBE_DEFINE0_XLATE(prov, mod, func, name); SDT_PROBE_DEFINE1_XLATE(prov, mod, func, name, arg0, xarg0); SDT_PROBE_DEFINE2_XLATE(prov, mod, func, name, arg0, xarg0, arg1, xarg1); SDT_PROBE_DEFINE3_XLATE(prov, mod, func, name, arg0, xarg0, arg1, xarg1, arg2, xarg2); SDT_PROBE_DEFINE4_XLATE(prov, mod, func, name, arg0, xarg0, arg1, xarg1, arg2, xarg2, arg3, xarg3); SDT_PROBE_DEFINE5_XLATE(prov, mod, func, name, arg0, xarg0, arg1, xarg1, arg2, xarg2, arg3, xarg3, arg4, xarg4); SDT_PROBE_DEFINE6_XLATE(prov, mod, func, name, arg0, xarg0, arg1, xarg1, arg2, xarg2, arg3, xarg3, arg4, xarg4, arg5, xarg5); SDT_PROBE_DEFINE7_XLATE(prov, mod, func, name, arg0, xarg0, arg1, xarg1, arg2, xarg2, arg3, xarg3, arg4, xarg4, arg5, xarg5, arg6, xarg6); SDT_PROBE0(prov, mod, func, name); SDT_PROBE1(prov, mod, func, name, arg0); SDT_PROBE2(prov, mod, func, name, arg0, arg1); SDT_PROBE3(prov, mod, func, name, arg0, arg1, arg2); SDT_PROBE4(prov, mod, func, name, arg0, arg1, arg2, arg3); SDT_PROBE5(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4); SDT_PROBE6(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4, arg5); SDT_PROBE7(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4, arg5, arg6); DESCRIPTION
The SDT macros allow programmers to define static trace points in kernel code. These trace points are used by the SDT framework to create DTrace probes, allowing the code to be instrumented using dtrace(1). By default, SDT trace points are disabled and have no effect on the surrounding code. When a DTrace probe corresponding to a given trace point is enabled, threads that execute the trace point will call a han- dler and cause the probe to fire. Moreover, trace points can take arguments, making it possible to pass data to the DTrace framework when an enabled probe fires. Multiple trace points may correspond to a single DTrace probe, allowing programmers to create DTrace probes that correspond to logical system events rather than tying probes to specific code execution paths. For instance, a DTrace probe corresponding to the arrival of an IP packet into the network stack may be defined using two SDT trace points: one for IPv4 packets and one for IPv6 packets. In addition to defining DTrace probes, the SDT macros allow programmers to define new DTrace providers, making it possible to namespace logi- cally-related probes. An example is FreeBSD's sctp provider, which contains SDT probes for FreeBSD's sctp(4) implementation. The SDT_PROVIDER_DECLARE() and SDT_PROVIDER_DEFINE() macros are used respectively to declare and define a DTrace provider named prov with the SDT framework. A provider need only be defined once; however, the provider must be declared before defining any SDT probes belonging to that provider. Similarly, the SDT_PROBE_DECLARE() and SDT_PROBE_DEFINE*() macros are used to declare and define DTrace probes using the SDT framework. Once a probe has been defined, trace points for that probe may be added to kernel code. DTrace probe identifiers consist of a provider, module, function and name, all of which may be specified in the SDT probe definition. Note that probes should not specify a module name: the module name of a probe is used to determine whether or not it should be destroyed when a kernel module is unloaded. See the BUGS section. Note in particular that probes must not be defined across multiple kernel modules. If '-' character (dash) is wanted in a probe name, then it should be represented as '__' (double underscore) in the probe name parameter passed to various SDT_*() macros, because of technical reasons (a dash is not valid in C identifiers). The SDT_PROBE_DEFINE*() macros also allow programmers to declare the types of the arguments that are passed to probes. This is optional; if the argument types are omitted (through use of the SDT_PROBE_DEFINE() macro), users wishing to make use of the arguments will have to manu- ally cast them to the correct types in their D scripts. It is strongly recommended that probe definitions include a declaration of their argument types. The SDT_PROBE_DEFINE*_XLATE() macros are used for probes whose argument types are to be dynamically translated to the types specified by the corresponding xarg arguments. This is mainly useful when porting probe definitions from other operating systems. As seen by dtrace(1), the arguments of a probe defined using these macros will have types which match the xarg types in the probe definition. However, the arguments passed in at the trace point will have types matching the native argument types in the probe definition, and thus the native type is dynami- cally translated to the translated type. So long as an appropriate translator is defined in /usr/lib/dtrace, scripts making use of the probe need not concern themselves with the underlying type of a given SDT probe argument. The SDT_PROBE*() macros are used to create SDT trace points. They are meant to be added to executable code and can be used to instrument the code in which they are called. EXAMPLES
The following probe definition will create a DTrace probe called 'icmp::unreach:pkt-receive', which would hypothetically be triggered when the kernel receives an ICMP packet of type Destination Unreachable: SDT_PROVIDER_DECLARE(icmp); SDT_PROBE_DEFINE1(icmp, , unreach, pkt__receive, "struct icmp *"); This particular probe would take a single argument: a pointer to the struct containing the ICMP header for the packet. Note that the module name of this probe is not specified. Consider a DTrace probe which fires when the network stack receives an IP packet. Such a probe would be defined by multiple tracepoints: SDT_PROBE_DEFINE3(ip, , , receive, "struct ifnet *", "struct ip *", "struct ip6_hdr *"); int ip_input(struct mbuf *m) { struct ip *ip; ... ip = mtod(m, struct ip *); SDT_PROBE3(ip, , , receive, m->m_pkthdr.rcvif, ip, NULL); ... } int ip6_input(struct mbuf *m) { struct ip6_hdr *ip6; ... ip6 = mtod(m, struct ip6_hdr *); SDT_PROBE3(ip, , , receive, m->m_pkthdr.rcvif, NULL, ip6); ... } In particular, the probe should fire when the kernel receives either an IPv4 packet or an IPv6 packet. Consider the ICMP probe discussed above. We note that its second argument is of type struct icmp, which is a type defined in the FreeBSD kernel to represent the ICMP header of an ICMP packet, defined in RFC 792. Linux has a corresponding type, struct icmphdr, for the same pur- pose, but its field names differ from FreeBSD's struct icmp. Similarly, illumos defines the icmph_t type, again with different field names. Even with the 'icmp:::pkt-receive' probes defined in all three operating systems, one would still have to write OS-specific scripts to extract a given field out of the ICMP header argument. Dynamically-translated types solve this problem: one can define an OS-independent c(7) struct to represent an ICMP header, say struct icmp_hdr_dt, and define translators from each of the three OS-specific types to struct icmp_hdr_dt, all in the dtrace(1) library path. Then the FreeBSD probe above can be defined with: SDT_PROBE_DEFINE1_XLATE(ip, , , receive, "struct icmp *", "struct icmp_hdr_dt *"); SEE ALSO
dtrace(1) AUTHORS
DTrace and the SDT framework were originally ported to FreeBSD from Solaris by John Birrell <jb@FreeBSD.org>. This manual page was written by Mark Johnston <markj@FreeBSD.org>. BUGS
The SDT macros allow the module name of a probe to be specified as part of a probe definition. However, the DTrace framework uses the module name of probes to determine which probes should be destroyed when a kernel module is unloaded, so the module name of a probe should match the name of the module in which its defined. SDT will set the module name properly if it is left unspecified in the probe definition; see the EXAMPLES section. One of the goals of the original SDT implementation (and by extension, of FreeBSD's port) is that inactive SDT probes should have no perfor- mance impact. This is unfortunately not the case; SDT trace points will add a small but non-zero amount of latency to the code in which they are defined. A more sophisticated implementation of the probes will help alleviate this problem. BSD
September 18, 2014 BSD
All times are GMT -4. The time now is 03:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy