Sponsored Content
Top Forums Shell Programming and Scripting Ps command and awk - shorten characters Post 302897200 by Akshay Hegde on Friday 11th of April 2014 02:49:08 PM
Old 04-11-2014
You may try something like this,

Code:
awk '{x = index($0,$4);$0 = substr($0,1,x-1) substr($0,x,60)}1'

Code:
ps -e -o pcpu -o pid -o user -o args | sort -k 1 | tail -6r | awk '{x = index($0,$4);$0 = substr($0,1,x-1) substr($0,x,60)}1'


Last edited by Akshay Hegde; 04-11-2014 at 04:23 PM.. Reason: replacement of match with index for simplification..
This User Gave Thanks to Akshay Hegde For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Howto shorten script in a busybox environment by using for loops?

My satellite receiver is equipped with busybox, so a small linux version. That is why I can not use certain commands like #tomorrow in date commands or #date -d "+1 day" and thus I have to use: day1=$ I want to download every day 6 files from the internet but the filenames consist of the date... (6 Replies)
Discussion started by: ni_hao
6 Replies

2. Shell Programming and Scripting

Using awk with the date command and escape characters

I have a file that is a log file for web traffic. I would like to convert the timestamp in it to unix time or epoch time. I am using the date command in conjunction with awk to try to do this. Just myfile: 28/Aug/1995:00:00:38 1 /pub/atomicbk/catalog/home.gif 813 28/Aug/1995:00:00:38 1... (3 Replies)
Discussion started by: jontjioe
3 Replies

3. Shell Programming and Scripting

awk command in script gives error while same awk command at prompt runs fine: Why?

Hello all, Here is what my bash script does: sums number columns, saves the tot in new column, outputs if tot >= threshold val: > cat getnon0file.sh #!/bin/bash this="getnon0file.sh" USAGE=$this" InFile="xyz.38" Min="0.05" # awk '{sum=0; for(n=2; n<=NF; n++){sum+=$n};... (4 Replies)
Discussion started by: catalys
4 Replies

4. Shell Programming and Scripting

script to shorten usernames and output to file

Hopefully someone here can point me in the correct direction. I'm working on a username migration and am trying to map my users ols usernames to the new ones. Right now every user has a username of firstname.lastname i.e. john.doe I'm trying to create a bash or python script that will take... (3 Replies)
Discussion started by: binary-ninja
3 Replies

5. Shell Programming and Scripting

Awk command to replace specific position characters.

Hi, I have a fixed width file. The way this file works is say for example there are 30 columns in it each with different sizes say 10,5,2, etc... If data in a field is less than the field size the rest of it is loaded with spaces. I would like an awk command to that would replace I have... (8 Replies)
Discussion started by: pinnacle
8 Replies

6. UNIX for Dummies Questions & Answers

How to shorten my code?

salary_range_report() { echo -e ${underline}$redYellow"\nSalary Range Report\n" tput sgr0 count_0_to_999=0 count_1000_to_2999=0 count_2000_to_5999=0 count_6000_to_9999=0 count_10000_above=0 for i in `cut -d "," -f4 $PAYROLL` #Loop Salary do if && then let... (4 Replies)
Discussion started by: eggisbad
4 Replies

7. UNIX for Dummies Questions & Answers

How can i use function for the below script to shorten it?

Hi All, i worte a shell script which will zcat the .gz file and write it in to a tmp file and then again cat the file and convert it to Dos mode. Next step is i am greping the file to search for the particular string on the 1st line and if the string does not exits it will insert the 1st line... (1 Reply)
Discussion started by: vikatakavi
1 Replies

8. Shell Programming and Scripting

Shorten header of protein sequences in fasta file

I have a fasta file as follows >sp|O15090|FABP4_HUMAN Fatty acid-binding protein, adipocyte OS=Homo sapiens GN=FABP4 PE=1 SV=3 MCDAFVGTWKLVSSENFDDYMKEVGVGFATRKVAGMAKPNMIISVNGDVITIKSESTFKN TEISFILGQEFDEVTADDRKVKSTITLDGGVLVHVQKWDGKSTTIKRKREDDKLVVECVM KGVTSTRVYERA >sp|L18484|AP2A2_RAT AP-2... (3 Replies)
Discussion started by: alexypaul
3 Replies

9. Shell Programming and Scripting

Shorten header of protein sequences in fasta file to only organism name

I have a fasta file as follows >sp|Q8WWQ8|STAB2_HUMAN Stabilin-2 OS=Homo sapiens OX=9606 GN=STAB2 PE=1 SV=3 MMLQHLVIFCLGLVVQNFCSPAETTGQARRCDRKSLLTIRTECRSCALNLGVKCPDGYTM ITSGSVGVRDCRYTFEVRTYSLSLPGCRHICRKDYLQPRCCPGRWGPDCIECPGGAGSPC NGRGSCAEGMEGNGTCSCQEGFGGTACETCADDNLFGPSCSSVCNCVHGVCNSGLDGDGT... (3 Replies)
Discussion started by: jerrild
3 Replies
TASKSET(1)							   User Commands							TASKSET(1)

NAME
taskset - retrieve or set a process's CPU affinity SYNOPSIS
taskset [options] mask command [arg]... taskset [options] -p [mask] pid DESCRIPTION
taskset is used to set or retrieve the CPU affinity of a running process given its PID or to launch a new COMMAND with a given CPU affin- ity. CPU affinity is a scheduler property that "bonds" a process to a given set of CPUs on the system. The Linux scheduler will honor the given CPU affinity and the process will not run on any other CPUs. Note that the Linux scheduler also supports natural CPU affinity: the scheduler attempts to keep processes on the same CPU as long as practical for performance reasons. Therefore, forcing a specific CPU affinity is useful only in certain applications. The CPU affinity is represented as a bitmask, with the lowest order bit corresponding to the first logical CPU and the highest order bit corresponding to the last logical CPU. Not all CPUs may exist on a given system but a mask may specify more CPUs than are present. A retrieved mask will reflect only the bits that correspond to CPUs physically on the system. If an invalid mask is given (i.e., one that corresponds to no valid CPUs on the current system) an error is returned. The masks are typically given in hexadecimal. For example, 0x00000001 is processor #0 0x00000003 is processors #0 and #1 0xFFFFFFFF is all processors (#0 through #31). When taskset returns, it is guaranteed that the given program has been scheduled to a legal CPU. OPTIONS
-a, --all-tasks Set or retrieve the CPU affinity of all the tasks (threads) for a given PID. -p, --pid Operate on an existing PID and do not launch a new task. -c, --cpu-list Specify a numerical list of processors instead of a bitmask. The numbers are separated by commas and may include ranges. For exam- ple: 0,5,7,9-11. -h, --help Display usage information and exit. -V, --version Display version information and exit. USAGE
The default behavior is to run a new command with a given affinity mask: taskset mask command [arguments] You can also retrieve the CPU affinity of an existing task: taskset -p pid Or set it: taskset -p mask pid PERMISSIONS
A user must possess CAP_SYS_NICE to change the CPU affinity of a process. Any user can retrieve the affinity mask. AUTHOR
Written by Robert M. Love. COPYRIGHT
Copyright (C) 2004 Robert M. Love This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. SEE ALSO
chrt(1), nice(1), renice(1), sched_setaffinity(2), sched_getaffinity(2) See sched_setscheduler(2) for a description of the Linux scheduling scheme. AVAILABILITY
The taskset command is part of the util-linux package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux/. util-linux April 2003 TASKSET(1)
All times are GMT -4. The time now is 07:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy