Define an alias with an embeded awk command ??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Define an alias with an embeded awk command ??
# 1  
Old 05-29-2007
Network Define an alias with an embeded awk command ??

Hi all,

I'm trying to define an alias with an embeded awk command:

alias kpipe='kill `psme| grep "ifw -r" | grep -v "grep ifw -r"| awk '{print $2}'`'

The problem is that the awk command (awk '{print $2}') contains two ' ..' quotes. So bash assumes that the first awk quote corresponds to the end of the alias, but it's not. I want it to process till the last ' .

How do I do it ? Any help will be highly appreciated.

note: I'm using bash shell.

Thanks for you help.
# 2  
Old 05-30-2007
Need More details...

Please provide the output of psme command...
# 3  
Old 05-30-2007
Data

psme output:

tstuser 63122 rating
oppuser 12134 javapps

meaning: first column is the user , second is the process id, third is the application name

Cheers.
# 4  
Old 05-30-2007
Try This...

alias fnm='ls -ltr | awk {print $9}'
# 5  
Old 05-30-2007
Code:
alias kpipe='kill `psme| grep "ifw -r" | grep -v "grep ifw -r"| awk "{print \\$2}"`'

or
Code:
alias kpipe="kill \`psme| grep 'ifw -r' | grep -v 'grep ifw -r'| awk '{print \$2}'\`"

You can simplify a little bit your command :
Replace
Code:
grep "ifw -r" | grep -v "grep ifw -r"

by
Code:
grep "[i]fw -r"

Another simplification : group grep and awk in a single awk command :
Code:
awk "/[i]ifw -r/ { print \\$2 }"

Jean-Pierre.
# 6  
Old 06-05-2007
MySQL Resolved

Hi all,

Thanks for your suggestions.

This one:
alias kpipe='kill `psme| grep "ifw -r" | grep -v "grep ifw -r"| awk "{print \\$2}"`'

worked perfectly.

Regards,
Joao.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Increment with awk - how to define start value

Hello, I am running under ubuntu18.04 My question is about awk. inputfile 0wo010011oasasds sdjhsdjh=, u12812888 8jsjkahsjajnsanakn akjskjskj=, suhuhuhwx kskkxmsnnxsnjxsnjxsnjjnjjdi=, 22878ssssss Below code adds consecutive numbers when string = is found run_code: awk -F'=' -v OFS='='... (4 Replies)
Discussion started by: baris35
4 Replies

2. Shell Programming and Scripting

To define a sender name in mail command

Hi, I am using the unix script to send a report on daily basis using the mail command. Here the sender name is appearing as myname i.e. chandru (userid@machine.unix.domain.com). Is there any way to change sender name as a user defined name? example i need to change it to SupportTeam... (1 Reply)
Discussion started by: schandru
1 Replies

3. Shell Programming and Scripting

Embeded shell variable in command line

Hello, I know this is a situation about the single quote and double literal, but I could not figure out after many search. I need to loop through thousands of different BACs sequencing to optimize kmer individually. IN=/PATH/TO/INPUT/FILES for sample in S{01..1096} do run_program... (9 Replies)
Discussion started by: yifangt
9 Replies

4. Shell Programming and Scripting

Define Alias for Changing Directory to Another One

Hello Friends is it possible to define an alias (say named as COMMAND) to pick a part of line and change my directory to picked. For example when I type COMMAND mfong@vhl.gov.nd/homefolder/hhk/ADS/ it would do cd /homefolder/hhk/ADS/ (1 Reply)
Discussion started by: rpf
1 Replies

5. Shell Programming and Scripting

Alias problem with awk command

Hi to all, I'm facing some problems when adding an alias like: #alias list="ls -al | awk '{ print $1, $2, $3, $4, (($5/1048576))"\t", $6, $7, $8, $9 }'" and when I enter: #list I get: Syntax Error The source line is 1. The error context is { print >>> , <<< awk:... (3 Replies)
Discussion started by: enux
3 Replies

6. Shell Programming and Scripting

How to alias an awk command with single and double quotes?

Hi, I am trying to write the following command as an alias in my .bashrc file. bjobs -u all | awk '{if (NR > 1) {username++;}}END{{print"\nJOBS BY USER:\n"} for (i in username) {print username,i;}{print"\n Total Jobs=",NR-1,"\n" }}' The command simply puts how many jobs each user is... (2 Replies)
Discussion started by: jacekmaciek
2 Replies

7. Shell Programming and Scripting

problem in embeded command substitution

$ echo $(tty|sed 's#/*/##') pts/0 $ who | grep $(tty|sed 's#/*/##') grep: 0652-033 Cannot open 0551-011. grep: 0652-033 Cannot open Standard. grep: 0652-033 Cannot open input. grep: 0652-033 Cannot open is. grep: 0652-033 Cannot open not. grep: 0652-033 Cannot open a. grep: 0652-033 Cannot... (2 Replies)
Discussion started by: wrl
2 Replies

8. UNIX for Dummies Questions & Answers

How to create alias with awk command

Good morning I would like kindly to ask you to help me with creation of alias with awk command. alias a="awk {print $1 "| " $2 "| " $3 "| " $4 "| " $5 "| " $6 "| " $7 "| " $8 "| " $13 "| " }" there is some error but I don't find it please explain me what is error and how can be avoid... (5 Replies)
Discussion started by: papa1980
5 Replies

9. Shell Programming and Scripting

AWK embeded PERL

Hello Guys, I am refering to this great forum once again for help. After various attempts at this, I am still failing to obtain the desire effect. I have to write a perl script which: 1- reads two values from the user (e.g name & passwd) 2- check each value against a file containing the... (7 Replies)
Discussion started by: bionicfysh
7 Replies

10. Shell Programming and Scripting

How to define two variable in foreach command??

Hello, I just want to know how If it's possiple to define 2 variable using foreach command ??? I have directory inside that directory around 1000 file, I want to rename all of this files to something I have it in a list. Example :- ------This is what in my directory---------- d1 d2... (14 Replies)
Discussion started by: geoquest
14 Replies
Login or Register to Ask a Question