Sponsored Content
Full Discussion: combining fields in awk
Top Forums Shell Programming and Scripting combining fields in awk Post 302213234 by json4639 on Wednesday 9th of July 2008 03:18:29 PM
Old 07-09-2008
combining fields in awk

I am using:

ps -A -o command,%cpu

to get process and cpu usage figures. I want to use awk to split up the columns it returns. If I use:

awk '{print "Process: "$1"\nCPU Usage: "$NF"\n"}'

the $NF will get me the value in the last column, but if there is more than one word in the process name (such as sshd jason), it only displays the first word in the column.

Does anyone know of a way to combine all the fields except the last one into one field, or some other way around this problem? I searched the forum for similar posts but didn't find any.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

combining fields in two text fields

Can someone tell me how to do this using sed, awk, or any other basic shell scripting? Basically I have two text files with the following contained in each file: File A: a b c d e f g h i File B: 1 2 3 I want the final outcome to look like this: a b c 1 d e f 2 g h i 3 How... (3 Replies)
Discussion started by: shocker
3 Replies

2. Shell Programming and Scripting

To get an output by combining fields from two different files

Hi guys, I couldn't find solution to this problem. If anyone knows please help me out. your guidance is highly appretiated. I have two files - FILE1 has the following 7 columns ( - has been added to make columns visible enough else columns are separated by single space) 155.34 - leg - 1... (8 Replies)
Discussion started by: smriti_shridhar
8 Replies

3. Shell Programming and Scripting

AWK Matching Fields and Combining Files

Hello! I am writing a program to run through two large lists of data (~300,000 rows), find where rows in one file match another, and combine them based on matching fields. Due to the large file sizes, I'm guessing AWK will be the most efficient way to do this. Overall, the input and output I'm... (5 Replies)
Discussion started by: Michelangelo
5 Replies

4. Shell Programming and Scripting

awk sed cut? to rearrange random number of fields into 3 fields

I'm working on formatting some attendance data to meet a vendors requirements to upload to their system. With some help on the forums here, I have the data close. But they've since changed what they want. The vendor wants me to submit three fields to them. Field 1 is the studentid field,... (4 Replies)
Discussion started by: axo959
4 Replies

5. Shell Programming and Scripting

Formatting and combining fields of the input file

Hi, I have a file of the following format: AV 103 AV 104 AV 105 AV 308 AV 517 BN 210 BN 211 BN 212 BN 218 and the desired output is : AV 103-105 3 AV 308 1 AV 517 1 BN 210-212 3 (5 Replies)
Discussion started by: rochitsharma
5 Replies

6. Shell Programming and Scripting

awk problem - combining awk statements

i have a datafile that has several lines that look like this: 2,dataflow,Sun Mar 17 16:50:01 2013,1363539001,2990,excelsheet,660,mortar,660,4 using the following command: awk -F, '{$3=strftime("%a %b %d %T %Y,%s",$3)}1' OFS=, $DATAFILE | egrep -v "\-OLDISSUES," | ${AWK} "/${MONTH} ${DAY}... (7 Replies)
Discussion started by: SkySmart
7 Replies

7. Shell Programming and Scripting

Join fields comparing 4 fields using awk

Hi All, I am looking for an awk script to do the following Join the fields together only if the first 4 fields are same. Can it be done with join function in awk?? a,b,c,d,8,,, a,b,c,d,,7,, a,b,c,d,,,9, a,b,p,e,8,,, a.b,p,e,,9,, a,b,p,z,,,,9 a,b,p,z,,8,, desired output: ... (1 Reply)
Discussion started by: aksijain
1 Replies

8. Shell Programming and Scripting

How to print 1st field and last 2 fields together and the rest of the fields after it using awk?

Hi experts, I need to print the first field first then last two fields should come next and then i need to print rest of the fields. Input : a1,abc,jsd,fhf,fkk,b1,b2 a2,acb,dfg,ghj,b3,c4 a3,djf,wdjg,fkg,dff,ggk,d4,d5 Expected output: a1,b1,b2,abc,jsd,fhf,fkk... (6 Replies)
Discussion started by: 100bees
6 Replies

9. Shell Programming and Scripting

awk - compare 1st 15 fields of record with 20 fields

I'm trying to compare 2 files for differences in a selct number of fields. When differnces are found it will write the whole record of the second file including appending '|C' out to a delta file. Each record will have 20 fields, but only want to do comparison of 1st 15 fields. The 1st field of... (7 Replies)
Discussion started by: sljnk
7 Replies

10. Shell Programming and Scripting

awk sort based on difference of fields and print all fields

Hi I have a file as below <field1> <field2> <field3> ... <field_num1> <field_num2> Trying to sort based on difference of <field_num1> and <field_num2> in desceding order and print all fields. I tried this and it doesn't sort on the difference field .. Appreciate your help. cat... (9 Replies)
Discussion started by: newstart
9 Replies
PMIE2COL(1)						      General Commands Manual						       PMIE2COL(1)

NAME
pmie2col - convert pmie output to multi-column format SYNOPSIS
pmie2col [-d delimiter] [-p precision] [-w width] DESCRIPTION
pmie2col is a simple tool that converts output from pmie(1) into regular column format. Each column is 7 characters wide (by default, may be changed with the -w option) with a single space between columns. That single space can be substituted with an alternate delimiter using the -d option (this is useful for importing the data into a spreadsheet, for example). The precision of the tabulated values from pmie can be specified with the -p option (default is 2 decimal places). This option can and will override any width setting in order to present the requested precision. The pmie(1) configuration must follow these rules: (1) Each pmie(1) expression is of the form ``NAME = expr;''. NAME will be used as the column heading, and must contain no white space, although special characters can be escaped by enclosing NAME in single quotes. (2) The ``expr'' must be a valid pmie(1) expression that produces a singular value. In addition, pmie(1) must be run with the -v command line option. It is also possible to use the -e command line to pmie(1) and output lines will be prefixed by a timestamp. EXAMPLE
Given this pmie(1) configuration file (config): loadav = kernel.all.load #'1 minute'; '%usr' = kernel.all.cpu.user; '%sys' = kernel.all.cpu.sys; '%wio' = kernel.all.cpu.wait.total; '%idle' = kernel.all.cpu.idle; 'max-iops' = max_inst(disk.dev.total); Then this command pipeline: $ pmie -v -t 5 <config | pmie2col -w 8 Produces output like this: loadav %usr %sys %wio %idle max-iops 0.21 ? ? ? ? ? 0.36 0.49 0.03 0.18 0.29 25.40 0.49 0.41 0.10 0.36 0.13 51.00 0.69 0.49 0.10 0.05 0.37 43.20 0.71 0.39 0.08 0.04 0.49 14.00 0.83 0.63 0.15 0.00 0.21 32.30 1.09 0.60 0.02 0.10 0.27 47.00 0.92 0.01 0.00 0.00 0.99 2.40 PCP ENVIRONMENT
Environment variables with the prefix PCP_ are used to parameterize the file and directory names used by PCP. On each installation, the file /etc/pcp.conf contains the local values for these variables. The $PCP_CONF variable may be used to specify an alternative configura- tion file, as described in pcp.conf(5). SEE ALSO
PCPIntro(1) and pmie(1). Performance Co-Pilot PCP PMIE2COL(1)
All times are GMT -4. The time now is 02:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy