usage of underscore in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting usage of underscore in awk
# 1  
Old 12-08-2008
usage of underscore in awk

Hi what is the purpose of using underscore in awk. I suppose it is for defining macro's and reducing repeatation but can some one show me an example?
# 2  
Old 12-08-2008
Could you give an example? I suppose it's a simple variable name without any special meaning (not like in Perl, for example).
# 3  
Old 12-08-2008
here is the example i found in one of the posts and there are many more similar posts.

Code:
awk -v ID=$ID '$NF==ID{_=1} !NF && _{exit}_'  file > request_id_data.txt

# 4  
Old 12-08-2008
It's an ordinary AWK variable, it's the same as:

Code:
awk -v ID=$ID '$NF==ID{myvar=1} !NF && myvar{exit}myvar'

As far as my posts are concerned (the above is not mine, it's from danmero's post I think), it's just an attempt to make a boring code look nicer (like Apollinaire's poetrySmilie).

Last edited by radoulov; 12-08-2008 at 07:16 AM..
# 5  
Old 12-08-2008
Sorry Its not a relevant question. I have gone a bit lousy to read the posts properly.

Last edited by ahmedwaseem2000; 12-08-2008 at 07:09 AM..
# 6  
Old 12-08-2008
1 or 0 (true or false in boolean context) as far as the above example is concerned.
# 7  
Old 12-08-2008
radoulov -Thanks for your replies
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk split after second underscore in field

I am trying to split a tab-delimeted file using awk after the second _ in bold. The awk below is close but splits on the first _, and I am not sure how to use the second _. Thank you :). file chr1 92145889 92149424 NM_001195684_exon_0_10_chr1_92145900_r 0 - chr1 92161218 ... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

awk usage

Hi I have a file like this user="joe" phone="4280919" duration=128 login=12/02/2016 ip-address=10.230.120.35 user="mary" phone="6352728" duration=23 login=16/02/2016 ip-address=10.123.231.54 I have to convert these to as follows (csv format) (Ignore Login field)... (6 Replies)
Discussion started by: Balav
6 Replies

3. Shell Programming and Scripting

Help with awk - Disk usage

Hi All, Would appreciate your help as to why the following code not showing the correct output. the issue is on the last else cause. I am trying to report on disk space based on percentage usage. for some reason, it's showing output as OK even thou disk space is 90% !!!! any ideas why? thanks!!... (2 Replies)
Discussion started by: xcod3r
2 Replies

4. Shell Programming and Scripting

Usage of Int with NR in awk

Hello Everyone, I am new to awk and trying my hand with the diff codes and came across the below code today. It would be great if any of the Guru's help me to understand. awk '{filename = "sample_file" int((NR-1)/34) ".DAT"; print >> filename}' sample_file.DAT 34 is the no of lines each... (7 Replies)
Discussion started by: saratha14
7 Replies

5. Shell Programming and Scripting

Awk, function of underscore char.

Hello Friends, I would appreciate so much if you could explain how the underscores works at the following code? Sorry if it sounds a bit novice question. awk -F',' 'NR==FNR{_=1;next}!_{print}' exclude infile KR, Eagle (6 Replies)
Discussion started by: EAGL€
6 Replies

6. Shell Programming and Scripting

Using of gsub function in AWK to replace space by underscore

I must design a UNIX script to monitor files whose size is over a threshold of 5 MB in a specific UNIX directory I meet a problem during the for loop in my script. Some file names contain spaces. ls -lrt | awk '$5>=5000000 && length($8)==5 {gsub(/ /,"_",$9); print};' -rw-r--r-- 1 was61 ... (2 Replies)
Discussion started by: Scofield38
2 Replies

7. UNIX for Dummies Questions & Answers

awk FS usage problem

Hi All, I have a question about the usage of FS in awk and i appreciate if you can help me sort out what i'm doing wrong. I have a file with info ; separated and i just want to print the o/p of all fields ($1 -> $8) to the screen. As you can see it is very simple but i'm facing an error. ... (5 Replies)
Discussion started by: Dendany83
5 Replies

8. Shell Programming and Scripting

grep/awk usage

Hi everybody, i know this question is common on the forum and i've searched for my answer but haven't quite found it. I'm trying to extract some values from a number of log files which look like this: Peak Power Consumption: 0.20777 Watts Observed Average Power: 0.1414794247 Watts The... (9 Replies)
Discussion started by: aKiiY
9 Replies

9. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

10. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies
Login or Register to Ask a Question