How does Awk interpret $0!~


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How does Awk interpret $0!~
# 1  
Old 12-28-2010
How does Awk interpret $0!~

I know $0 is the entire file's contents (at least I think that is what it is!), but what exactly is: $0!~

This was a snippet from a larger line
Code:
awk '$0!~/^$/ {print $0}'

This deletes blank lines, but I want to know specifically the $0!~ part... I am guessing /^$/ is regex for blank line... and {print $0} means to print the whole thing to stdout.. Right?
# 2  
Old 12-28-2010
Yes.
~ == >> "match"
!~ == >> "no match"
It prints lines which doesn't match with regular exp ^$ i.e. blank.
So prints all non-blank lines only (i.e. delete blank lines)
# 3  
Old 12-28-2010
$0 is one record (line) from the file. $1 is field #1, $2 is field #2..... depending on your field separator.
# 4  
Old 12-29-2010
How do you search for a regex in awk that is case insensitive?

awk '$0~ /case-insensitive-regex-here/'

Nevermind, I guess I got it, is this the best way?
Code:
 awk 'tolower ($0)~ /case-insensitive-regex-here/'


Last edited by glev2005; 12-29-2010 at 10:53 AM..
# 5  
Old 12-29-2010
Quote:
Originally Posted by glev2005
How do you search for a regex in awk that is case insensitive?

awk '$0 /case-insensitive-regex-here/'
Using next instruction:
Code:
BEGIN { IGNORECASE = 1; }

Regards,
Birei
# 6  
Old 12-29-2010
Quote:
Originally Posted by birei
Using next instruction:
Code:
BEGIN { IGNORECASE = 1; }

Regards,
Birei
Works only with gawk.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Who -r interpret?

I booted into single user mode with /usr/sbin/reboot -- -s but after doing a control -d my who -r shows run-level 3 Nov 17 14:07 3 0 S I was expecting it to show run-level S why is this still in run level 3? thanks (1 Reply)
Discussion started by: goya
1 Replies

2. UNIX for Dummies Questions & Answers

Need to interpret code

hi All, i have never used sed in Unix environment, but i have one script which is using this following command: cat audit_session_rpt_MSP_20140331.lst|sed -n '/Apr 14/!p'| sed -n '/Page/!p'| sed -n '/UserName/!p' |\ egrep -v '^-|^=|^\*'|sed '/^$/d'|sed -e '1,7d'... (1 Reply)
Discussion started by: lovelysethii
1 Replies

3. Shell Programming and Scripting

don't know how to interpret this

Can anyone tell me how to interpret this: listpage="ls |more" (the spaces are there in the example) $listpage It's from my bash book and I'm not sure what it means (3 Replies)
Discussion started by: Straitsfan
3 Replies

4. Shell Programming and Scripting

Can someone interpret this -- not sure

Was wondering if someone could interpret this for me -- I'm not sure what everything means. It's a shell script from my bash book: cd () { builtin cd "$@" es=$? echo "$OLDPWD ->$PWD" return $es } what I don't quite understand is the "$@". I think, if I understand... (6 Replies)
Discussion started by: Straitsfan
6 Replies

5. UNIX for Dummies Questions & Answers

How to interpret TOP

Hi, So I am new to Unix, and I need to check the performance of some apps I am running. But I don't know how to interpret the output from TOP. Could somebody please explain the difference between the different values. And also explain how I can have a process which has a %CPU > 100? ... (7 Replies)
Discussion started by: dj_jay_smith
7 Replies

6. Shell Programming and Scripting

Interpret sed and awk in the below command.

Could you interpret the following sed and awk command for me? command: cat tempfile2 |sed "s/\(BUILD-3-.*-\.-\)\(.*\..*\..*\)/\2/" | awk '{printf "%-8.8s %-23.23s %-30.30s %-50.50s\n", $1,$2,$3,substr($0,index($0,$4))}' > outfile2 2>/dev/null input:data in tempfile2... (5 Replies)
Discussion started by: vj8436
5 Replies

7. Shell Programming and Scripting

Interpret the sed command.

Could you interpret the following sed and awk command for me? command: cat tempfile2 |sed "s/\(BUILD-3-.*-\.-\)\(.*\..*\..*\)/\2/" | awk '{printf "%-8.8s %-23.23s %-30.30s %-50.50s\n", $1,$2,$3,substr($0,index($0,$4))}' > outfile2 2>/dev/null input:(data in tempfile2)... (1 Reply)
Discussion started by: vj8436
1 Replies

8. UNIX for Dummies Questions & Answers

Please interpret.

Hi guys, I have no idea on unix but suddenly, my cobol programs calls a unix script that i know nothing about. can you guys interpret these lines for me? i know its a print command but I want to actually know how many copies it prints. qprt -da -P $1 -t '6' -i '6' -l '70' $2 qprt -da... (1 Reply)
Discussion started by: supacow
1 Replies

9. Shell Programming and Scripting

How Do We Interpret This ?

ksh $ETL_XXX/bin/filename.ksh wf_workflowname . Which is used in post session command. (2 Replies)
Discussion started by: dummy_needhelp
2 Replies

10. UNIX for Dummies Questions & Answers

sar -q - how to Interpret these results

Should I be concerned about the %runocc value be always 100. The CPU is 99% idle all the time and the paging is 0 MyMachine|10/23/2007 00:00:05|1.0|100|| MyMachine|10/23/2007 00:05:04|1.0|100|| MyMachine|10/23/2007 00:10:04|1.0|100|| MyMachine|10/23/2007 00:15:04|1.0|100||... (2 Replies)
Discussion started by: SarNovice
2 Replies
Login or Register to Ask a Question