Sponsored Content
Full Discussion: append data to each line
Top Forums Shell Programming and Scripting append data to each line Post 302363340 by jp2542a on Tuesday 20th of October 2009 05:14:10 AM
Old 10-20-2009
If I understand what you are looking to do, this awk script will take a list of pmap files of the form you presented and print a csv line with the pid and anon values found in all the pmap files. The anon values are in the order of the pmap files given on the command line.


(
Code:
FNR == 1) {

        getline   # skip to the pid
        this_pid = strtonum($1)
        if( this_pid in pid_list)
                pid_list[this_pid] = pid_list[this_pid] ","     # add a comma
        else
                pid_list[this_pid] = "%d,"              # set the format string
        next
}
/^total/ {              # look for total line

        pid_list[this_pid] = pid_list[this_pid] $5      # add anon total
}

END {
        for( i in pid_list )
                printf pid_list[i] "\n" , i
}

To use it, put the above code in a file (pid.awk in my example).
Then use a command of this form

Code:
awk -f pid.awk <list_of_pmap_file>

The <list_of_pmap_file> should be a wildcard spec or back tick command to produce a list of files in the order you want them processed.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Joining lines in reverse. append line 1 to line 2.

Hi I have used many times the various methods to append two lines together in a file. This time I want to append the 1st line to the second and repeat for the complete file.... an example This is the file owns the big brown dog joe owns the small black dog jim What I want is ... (7 Replies)
Discussion started by: dwalley
7 Replies

2. Shell Programming and Scripting

how to append line of of data to file

hai..i am new to unix..and i've currently learn shell script.. i have this small problem where i would like to save every data from log file into user directory if the data is equal to the name of the user.. i manage to do that with below script.. i would like to ask if there is any solutions so... (1 Reply)
Discussion started by: meggae
1 Replies

3. Programming

Append data to smallint data in informix4gl?

Hi, I have an smallint variable, say "a", i would like to prefix it with "0" in certain conditions. Is it possible to achieve that with this datatype? For instance, a=9 --> a=09 Many thanks (1 Reply)
Discussion started by: dvah
1 Replies

4. Shell Programming and Scripting

Match data based on two fields, and append to a line

I need to write a program to do something like a 'vlookup' in excel. I want to match data from file2 based on two fields (where both match) in file1, and for matching lines, add the data from two of the fields from file2 to file1. If anyone knows something in perl or awk that can do this, I'd be... (20 Replies)
Discussion started by: jamessmith01
20 Replies

5. Shell Programming and Scripting

Append next line to previous line when one pattern not found

Hi, I need help for below scenario.I have a flat file which is having records seperated by delimiters which will represent each record for oracle table.My Control file will consider each line as one record for that table. Some of the lines are aligned in two/three lines so that records are... (4 Replies)
Discussion started by: kannansr621
4 Replies

6. Shell Programming and Scripting

find a certain line and append text to the end of the line

After I create printer queues in AIX, I have to append a filter file location within that printers custom file. within lets say test_queue.txt I need to find the row that starts with :699 and then I need to append on the end the string /usr/local/bin/k_portrait.sh. Now I've gotten the sed... (2 Replies)
Discussion started by: peachclift
2 Replies

7. UNIX for Dummies Questions & Answers

How to remove fields space and append next line to previous line.?

awk 'BEGIN{FS = "Ç"} NR == 1 {p = $0; next} NF > 1 {print p; p = $0} NF <= 1 {p = (p " " $0)} END {print p}' input.txt > output.txt This is what the input data file looks like with broken lines Code: 29863 Ç890000000 Ç543209911 ÇCHNGOHG Ç000000001 Ç055 ... (4 Replies)
Discussion started by: cumeh1624
4 Replies

8. Shell Programming and Scripting

Append Next line with current Line bassed on condition

Hi, I have an XML file and I am tring to extract some data form it, after lot of data cleaning process, I ended up with an issue, and need your urgent support. my current input data in below format: <Node>xxxxxx <Node>yyyyy</Node> <Node>zzzzzz <Node>12345</node> I need... (9 Replies)
Discussion started by: rramkrishnas
9 Replies

9. Shell Programming and Scripting

To append new data at the end of each line based on substring of last column

Hi guys, I need to append new data at the end of each line of the files. This new data is based on substring (3rd fields) of last column. Input file xxx.csv: U1234|1-5X|orange|1-5X|Act|1-5X|0.1 /sac/orange 12345 0 U5678|1-7X|grape|1-7X|Act|1-7X|0.1 /sac/grape 5678 0... (5 Replies)
Discussion started by: null7
5 Replies

10. Shell Programming and Scripting

Remove new line starting with a numeric value and append it to the previous line

Hi, i have a file with multiple entries. After some tests with sed i managed to get the file output as follows: lsn=X-LINK-IN0,apc=661:0,state=avail,avail/links=1/1, 00,2110597,2094790,0,81,529,75649011,56435363, lsn=TM1ITP1-AM1ITP1-LS,apc=500:0,state=avail,avail/links=1/1,... (5 Replies)
Discussion started by: nms
5 Replies
tnfctl_trace_state_set(3TNF)				       TNF Library Functions				      tnfctl_trace_state_set(3TNF)

NAME
tnfctl_trace_state_set, tnfctl_filter_state_set, tnfctl_filter_list_get, tnfctl_filter_list_add, tnfctl_filter_list_delete - control kernel tracing and process filtering SYNOPSIS
cc [ flag ... ] file ... -ltnfctl [ library ... ] #include <tnf/tnfctl.h> tnfctl_errcode_t tnfctl_trace_state_set(tnfctl_handle_t *hndl, boolean_t trace_state); tnfctl_errcode_t tnfctl_filter_state_set(tnfctl_handle_t *hndl, boolean_t filter_state); tnfctl_errcode_t tnfctl_filter_list_get(tnfctl_handle_t *hndl, pid_t **pid_list, int *pid_count); tnfctl_errcode_t tnfctl_filter_list_add(tnfctl_handle_t *hndl, pid_t pid_to_add); tnfctl_errcode_t tnfctl_filter_list_delete(tnfctl_handle_t *hndl, pid_t pid_to_delete); DESCRIPTION
The interfaces to control kernel tracing and process filtering are used only with kernel handles, handles created by tnfctl_ker- nel_open(3TNF). These interfaces are used to change the tracing and filter states for kernel tracing. tnfctl_trace_state_set() sets the kernel global tracing state to "on" if trace_state is B_TRUE, or to "off" if trace_state is B_FALSE. For the kernel, trace_state is off by default. Probes that are enabled will not write out data unless this state is on. Use tnfctl_trace_attrs_get(3TNF) to retrieve the current tracing state. tnfctl_filter_state_set() sets the kernel process filtering state to "on" if filter_state is B_TRUE, or to "off" if filter_state is B_FALSE. filter_state is off by default. If it is on, only probe points encountered by processes in the process filter set by tnfctl_fil- ter_list_add() will generate trace points. Use tnfctl_trace_attrs_get(3TNF) to retrieve the current process filtering state. tnfctl_filter_list_get() returns the process filter list as an array in pid_list. The count of elements in the process filter list is returned in pid_count. The caller should use free(3C) to free memory allocated for the array pid_list. tnfctl_filter_list_add() adds pid_to_add to the process filter list. The process filter list is maintained even when the process filter- ing state is off, but it has no effect unless the process filtering state is on. tnfctl_filter_list_delete() deletes pid_to_delete from the process filter list. It returns an error if the process does not exist or is not in the filter list. RETURN VALUES
The interfaces tnfctl_trace_state_set(), tnfctl_filter_state_set(), tnfctl_filter_list_add(), tnfctl_filter_list_delete(), and tnfctl_fil- ter_list_get() return TNFCTL_ERR_NONE upon success. ERRORS
The following error codes apply to tnfctl_trace_state_set: TNFCTL_ERR_BADARG The handle is not a kernel handle. TNFCTL_ERR_NOBUF Cannot turn on tracing without a buffer being allocated. TNFCTL_ERR_BUFBROKEN Tracing is broken in the target. TNFCTL_ERR_INTERNAL An internal error occurred. The following error codes apply to tnfctl_filter_state_set: TNFCTL_ERR_BADARG The handle is not a kernel handle. TNFCTL_ERR_INTERNAL An internal error occurred. The following error codes apply to tnfctl_filter_list_add: TNFCTL_ERR_BADARG The handle is not a kernel handle. TNFCTL_ERR_NOPROCESS No such process exists. TNFCTL_ERR_ALLOCFAIL A memory allocation failure occurred. TNFCTL_ERR_INTERNAL An internal error occurred. The following error codes apply to tnfctl_filter_list_delete: TNFCTL_ERR_BADARG The handle is not a kernel handle. TNFCTL_ERR_NOPROCESS No such process exists. TNFCTL_ERR_INTERNAL An internal error occurred. The following error codes apply to tnfctl_filter_list_get: TNFCTL_ERR_BADARG The handle is not a kernel handle. TNFCTL_ERR_ALLOCFAIL A memory allocation failure occurred. TNFCTL_ERR_INTERNAL An internal error occurred. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWtnfc | +-----------------------------+-----------------------------+ |MT Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
prex(1), TNF_PROBE(3TNF), free(3C), libtnfctl(3TNF), tnfctl_kernel_open(3TNF), tnfctl_trace_attrs_get(3TNF), tracing(3TNF), tnf_ker- nel_probes(4), attributes(5) SunOS 5.10 4 Mar 1997 tnfctl_trace_state_set(3TNF)
All times are GMT -4. The time now is 02:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy