Sponsored Content
Full Discussion: How to alias this awk?
Top Forums UNIX for Dummies Questions & Answers How to alias this awk? Post 302966213 by Scrutinizer on Tuesday 9th of February 2016 02:07:27 PM
Old 02-09-2016
Try using a function instead of an alias, which allows you to use parameters:

Code:
x() {
  df -k "$1" | awk 'NR==1 {CNV=1024*1024;GBYTES="GBytes";FMT="%-35s %-10s %-10s %-10s %10s %-s\n"; printf FMT, $1, GBYTES, $3, $4, $5, $6; next} {printf FMT,$1,$2/CNV,$3/CNV,$4/CNV,$5,$6}'
}

Code:
x /tmp

--
It also allows you to make it more readable:
Code:
x() {
  df -k "$1" | 
  awk '
    NR==1 {
      CNV=1024*1024
      FMT="%-35s %-10s %-10s %-10s %10s %-s\n"
      printf FMT, $1, "GBYTES", $3, $4, $5, $6
      next
    }
    {
      printf FMT,$1,$2/CNV,$3/CNV,$4/CNV,$5,$6
    }
  '
}


Last edited by Scrutinizer; 02-09-2016 at 03:14 PM..
 

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

awk alias

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... (1 Reply)
Discussion started by: papa1980
1 Replies

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

4. Shell Programming and Scripting

AWK alias with parameters

Hello, How can I make an alias of an AWK one liner that prints specific lines from a file like below? # from a command like this: awk 'NR == 100, NR == 150' file.cfg The alias I want to make should work like this(I guess): <alias_command> <file.cfg><start_line><end_line> So the... (1 Reply)
Discussion started by: majormark
1 Replies

5. Shell Programming and Scripting

Alias to awk BEGIN statement

I'd like to define an alias to awk's begin statement since I use awk with different delimiters all the time and it is tiresome to type awk '{OFS="\t";FS="\t"}{BLAH BLAH}' every time. The problem is that bash won't let me make an alias with an open quote, which is necessary for the BEGIN alias to... (3 Replies)
Discussion started by: baconbasher
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. UNIX for Dummies Questions & Answers

using alias

I need to login to one server and then switch the user and set a number alias. But i cant modify the .profile file. I have one script avi1.sh $ more avi.sh sudo su - bil sh avi1.sh and in home directory of bil i have avi1.sh that says $ more avi1.sh alias l='ls -ltr' alias b='cd... (7 Replies)
Discussion started by: blackeyed
7 Replies

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

9. UNIX for Dummies Questions & Answers

Create alias files (not alias commands)

If one: $ find -name 'some expression' -type f > newfile and then subsequently wants to create an alias file from each pathname the find command retrieved and the > placed within 'newfile', how would one do this? Ideally, the newly created alias files would all be in one directory. I am... (3 Replies)
Discussion started by: Alexander4444
3 Replies

10. Shell Programming and Scripting

awk alias passing a value to a variable

I am trying to turn this into an alias with no luck. I would then like to put the alias into my bashrc file. I know awk is very picky about quotes. I have tried every version of quotes, single quotes, double quotes, and backslashes that I can think of. VAR=$(xrandr | awk '$2=="connected"{s=$1}... (3 Replies)
Discussion started by: cokedude
3 Replies
wml::fmt::all(3)						     EN Tools							  wml::fmt::all(3)

NAME
wml::fmt:all - All of Formatting (FMT) category SYNOPSIS
#use wml::fmt::all DESCRIPTION
This includes all existing include files of the Formatting (FMT) category, i.e. all includes with prefix wml::fmt. The following files currently exist: wml::fmt::isolatin(3) ... ISO-Latin-1 to HTML Entity Conversion wml::fmt::verbatim(3) ... Really Preformatted Verbatim Text wml::fmt::xtable(3) ... HTML tables through Advanced Syntax wml::fmt::url(3) ... Recognize Uniform Resource Locator wml::fmt::text(3) ... Plain ASCII with Special Formatting Semantic wml::fmt::pod(3) ... Plain Old Document (POD) Format wml::fmt::sdf(3) ... Simple Document Format (SDF) AUTHOR
Ralf S. Engelschall rse@engelschall.com www.engelschall.com REQUIRES
Internal: P1 External: -- SEE ALSO
wml::fmt::isolatin(3), wml::fmt::verbatim(3), wml::fmt::xtable(3), wml::fmt::url(3), wml::fmt::text(3), wml::fmt::pod(3), wml::fmt::sdf(3). EN Tools 2014-04-16 wml::fmt::all(3)
All times are GMT -4. The time now is 09:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy