Alias problem with awk command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Alias problem with awk command
# 1  
Old 12-17-2010
Alias problem with awk command

Hi to all,
I'm facing some problems when adding an alias like:
Code:
#alias list="ls -al | awk '{ print $1, $2, $3, $4, (($5/1048576))"\t", $6, $7, $8, $9 }'"

and when I enter:
Code:
#list

I get:

Code:
Syntax Error The source line is 1.
 The error context is
                { print >>>  , <<< 
 awk: 0602-502 The statement cannot be correctly parsed. The source line is 1.


I'm running ksh Version M-11/16/88f on AIX version 5.3
Can you tell where the problem can be?
Thanks
Enid

Last edited by Scott; 12-17-2010 at 12:07 PM.. Reason: Please use code tags
# 2  
Old 12-17-2010
The shell is evaluating $1, $2, etc, when you create the alias, not when you use it.

Try:
Code:
alias list="ls -al | awk '{ print \$1, \$2, \$3, \$4, ((\$5/1048576))\"\t\", \$6, \$7, \$8, \$9 }'"

(I tried with other combinations of quoting, but that didn't seem to work).

Not tested on AIX, but I can't imagine the syntax would be any different.

In fact, I will move this thread from the AIX sub-forum to the Shell Scripting sub-forum.
# 3  
Old 12-17-2010
Thanks scottn,

it worked pretty well on AIX (also on Ubuntu).

Regards.
# 4  
Old 12-17-2010
Sometimes it's easier - and more flexible - creating a function, or a script, instead of using aliases.

But glad it works Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Alias problem

Please forgive me if this is too stupid a question as I am fairly new to scripting. I have an alias in my .profile (ksh) like this: alias ff='find . -name $1' The idea is to find all files in current dir and all subdir with the name specified in the param passed. So, I issue the command:... (8 Replies)
Discussion started by: sssccc
8 Replies

2. Shell Programming and Scripting

getting problem in awk command

Hi, I have one file with tab delimited values in it. i want to increase the value of 6th field by 2 if value of 3rd field is greater than 2 . The command is working fine but space between the field is getting removed after adding. below is the file and the command Filename: test1.txt ... (13 Replies)
Discussion started by: ravi_agarwalla
13 Replies

3. Linux

mail alias problem

Hi all, well i am configuring backuppc for awhile, anyway my current problem is, i set a smarthost, configured the mail to use our ISP smtp server, and its working successfully thanks to ALLAH, now i want to set an alias for mails( it was working when it was using the local smtp server), so the... (0 Replies)
Discussion started by: XP_2600
0 Replies

4. OS X (Apple)

Problem using a top command alias in my profile

Hi- I am newish to the mac osx unix interface. I want to set up top so that it always displays the username. I can use this command to do this: top -ocpu -P ' PID COMMAND %CPU TIME #TH #PRTS #MREGS RPRVT RSHRD RSIZE VSIZE USER' -p '$aaaa ^bbbbbbbbb $cccc $wwwwwww $ee... (1 Reply)
Discussion started by: mikey11415
1 Replies

5. 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

6. Post Here to Contact Site Administrators and Moderators

AWK command problem

How can I write an AWK so it could print some fixed strings and concatenate that with other words from an input file. Also having a string like "go" in the next line in the output file as below: Example: A fixed string like: "Hello my" and the input file is: friend mother father... (4 Replies)
Discussion started by: sybase08
4 Replies

7. 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

8. UNIX for Dummies Questions & Answers

Alias problem

i'm trying to get the alias alias "sudo su"=`sh script.sh` whats wrong with this and how can i make an alias that has a space in it (1 Reply)
Discussion started by: cleansing_flame
1 Replies

9. Shell Programming and Scripting

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... (5 Replies)
Discussion started by: jfortes
5 Replies

10. UNIX for Dummies Questions & Answers

alias problem

How can I get two commands in one alias? In my exaple it only display the current date. alias two='cal | date' (5 Replies)
Discussion started by: Mattiax
5 Replies
Login or Register to Ask a Question