AWK alias with parameters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK alias with parameters
# 1  
Old 11-11-2008
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?
Code:
# 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 line numbers can be attached at the end of the file name like file.cfg_100_150 and the AWK should parse the file name first in order to get the lines(if that's possible).

Thanks.
# 2  
Old 11-11-2008
Basically it's like this:
Code:
root@isau02:/data/tmp/testfeld> cat infile
eins
zwei
drei
root@isau02:/data/tmp/testfeld> alias yo="awk 'NR == 2 {print}' \$1 > newfile"
root@isau02:/data/tmp/testfeld> yo ./infile
root@isau02:/data/tmp/testfeld> cat newfile
zwei

For the output file having the line numbers in it's name, I have no good short idea atm. Maybe someone else comes up with it or you try a bit too Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to alias this awk?

Hi, I am running the following df command to display df in GB. I am not able to use df -h on this server as that option is not available. df -k /tmp | 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... (3 Replies)
Discussion started by: newbie_01
3 Replies

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

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

4. Shell Programming and Scripting

Help with explanation of awk parameters

Hello, Would someone be able to tell me exactly how this command works please? awk '!x++' As usual any help much appreciated (8 Replies)
Discussion started by: Grueben
8 Replies

5. Shell Programming and Scripting

awk parameters check

Is there a way to preform check if the parameters that was send with the command awk -f `file_name.awk` `input_file` before even it gets to the BEGIN section (i have tested a try to check in the BEGIN it doesn't let ,you must make it on the section that after the BEGIN) and then decide if the... (1 Reply)
Discussion started by: tal
1 Replies

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

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

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

alias & parameters

We just recently moved from a DG-UX (Unix V) to HP 9000 servers running POSIX. I used the c-shell in the DG-UX system mainly because the bourne-shell did not support aliasing. Now in the default posix-shell of HP aliasing is supported. The main difference seams to be that in a c-shell you can pass... (1 Reply)
Discussion started by: vslewis
1 Replies
Login or Register to Ask a Question