Combining awk command to make it more efficient


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Combining awk command to make it more efficient
# 1  
Old 09-29-2016
Combining awk command to make it more efficient

Code:
VARIABLE="jhovan    5259  5241  0 20:11 ?        00:00:00 /proc/self/exe --type=gpu-process --channel=5182.0.1597089149 --supports-dual-gpus=false --gpu-driver-bug-workarounds=2,45,57 --disable-accelerated-video-decode --gpu-vendor-id=0x80ee --gpu-device-id=0xbeef --gpu-driver-vendor --gpu-driver-version --v8-natives-passed-by-fd --v8-snapshot-passed-by-fd"

current command i'm using:

Code:
echo "${VARIABLE}" | awk '/channel=5182/ && !/egrep|ps -ef|grep / && ($0 ~ /1597/) {print $0}' | awk -F"1597089149" '{print $2}' | awk '{print $1}'

How can i optimize this code? i'd like to do everything with one awk command? possibly even avoiding the "echo".

the expected output should be:

Code:
--supports-dual-gpus=false

# 2  
Old 09-29-2016
try this

Code:
ps -ef | awk '/[c]hannel=5182/{for(i=1;i<=NF;i++)if($i~/supports/)print $i}'

This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 09-29-2016
Quote:
Originally Posted by itkamaraj
try this

Code:
ps -ef | awk '/[c]hannel=5182/{for(i=1;i<=NF;i++)if($i~/supports/)print $i}'

this looks like it could work. but it assumes "supports" will always be in the position it is grabbed from. what im trying to do is print any pattern that is present in the position that "supports" is in.

for instance. the following text may be in the position:

Code:
/bin/ksh fashsearch.sh giraffes are great animals

in which case, what i want to do is print fastsearch.sh. essentially do what the following code is doing, but instead of using multiple commands, i'd like just one instance of awk to do everything.

Code:
ps -ef | awk -F"/bin/ksh" '{print $2}' | awk '{print $1}'

# 4  
Old 09-29-2016
Quote:
Originally Posted by SkySmart
this looks like it could work. but it assumes "supports" will always be in the position it is grabbed from. what im trying to do is print any pattern that is present in the position that "supports" is in.

for instance. the following text may be in the position:

Code:
/bin/ksh fashsearch.sh giraffes are great animals

in which case, what i want to do is print fastsearch.sh. essentially do what the following code is doing, but instead of using multiple commands, i'd like just one instance of awk to do everything.

Code:
ps -ef | awk -F"/bin/ksh" '{print $2}' | awk '{print $1}'

Perhaps something more like:
Code:
pattern="/bin/ksh"
ps -ef | awk -v pat="$pattern" '{for(i=1;i<NF;i++)if($i~pat)print $(i+1)}'

pattern="channel=5182"
ps -ef | awk -v pat="$pattern" '{for(i=1;i<NF;i++)if($i~pat)print $(i+1)}'

will give you what you want???
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to make awk command faster for large amount of data?

I have nginx web server logs with all requests that were made and I'm filtering them by date and time. Each line has the following structure: 127.0.0.1 - xyz.com GET 123.ts HTTP/1.1 (200) 0.000 s 3182 CoreMedia/1.0.0.15F79 (iPhone; U; CPU OS 11_4 like Mac OS X; pt_br) These text files are... (21 Replies)
Discussion started by: brenoasrm
21 Replies

2. Shell Programming and Scripting

How to make awk command faster?

I have the below command which is referring a large file and it is taking 3 hours to run. Can something be done to make this command faster. awk -F ',' '{OFS=","}{ if ($13 == "9999") print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12 }' ${NLAP_TEMP}/hist1.out|sort -T ${NLAP_TEMP} |uniq>... (13 Replies)
Discussion started by: Peu Mukherjee
13 Replies

3. Shell Programming and Scripting

More efficient awk parser

I have an awk parser, that works great if the data is NC_0000 (four digits), but if it is not that then the data is parsed. I'm not sure the most efficient way to obtain the desired output. Thank you :). Code: awk 'FNR > 1 && match($0, /NC_0000(*)\..*g\.(+)(.)>(.)/, a){ print a, a, a, a, a }'... (14 Replies)
Discussion started by: cmccabe
14 Replies

4. Shell Programming and Scripting

Combining awk printf and print strftime command

I have a lines like below, captured from rrdtool fetch command, 1395295200 2.0629986254e+06 7.4634784967e+05 1395297000 2.0198121616e+06 6.8658888903e+05 1395298800 1.8787141122e+06 6.7482866452e+05 1395300600 1.7586118678e+06 6.7867977653e+05 1395302400 1.8222762151e+06 7.1301678859e+05I'm... (3 Replies)
Discussion started by: rk4k
3 Replies

5. Programming

Help with make this Fortran code more efficient (in HPC manner)

Hi there, I had run into some fortran code to modify. Obviously, it was written without thinking of high performance computing and not parallelized... Now I would like to make the code "on track" and parallel. After a whole afternoon thinking, I still cannot find where to start. Can any one... (3 Replies)
Discussion started by: P_E_M_Lee
3 Replies

6. Emergency UNIX and Linux Support

Help to make awk script more efficient for large files

Hello, Error awk: Internal software error in the tostring function on TS1101?05044400?.0085498227?0?.0011041461?.0034752266?.00397045?0?0?0?0?0?0?11/02/10?09/23/10???10?no??0??no?sct_det3_10_20110516_143936.txt What it is It is a unix shell script that contains an awk program as well as... (4 Replies)
Discussion started by: script_op2a
4 Replies

7. UNIX for Advanced & Expert Users

Which cut command is more efficient?

Hi, I've got a query regarding which of the following is more efficient & why - cat <filename>|cut -d'*' -f2- > <newfilename> or cut -d'*' -f2- <filename> > <newfilename> Thanks. (17 Replies)
Discussion started by: sumoka
17 Replies

8. Shell Programming and Scripting

Is there a way to make this more efficient

I have the following code. printf "Test Message Report" > report.txt while read line do msgid=$(printf "%n" "$line" | cut -c1-6000| sed -e 's///g' -e 's|.*ex:Msg\(.*\)ex:Msg.*|\1|') putdate=$(printf "%n" "$line" | cut -c1-6000| sed -e 's///g' -e 's|.*PutDate\(.*\)PutTime.*|\1|')... (9 Replies)
Discussion started by: gugs
9 Replies

9. Shell Programming and Scripting

Efficient way of Awk

Hi, Can someone let me know if the below AWK can be made much simpler / efficient ? I have 200 fields, I need to substr only the last fields. So i'm printing awk -F~ 'print {$1, $2, $3....................................$196,$197 , susbstr($198,1,3999), substr($199,1,3999)..}' Is there a... (4 Replies)
Discussion started by: braindrain
4 Replies
Login or Register to Ask a Question