how to display some special results with AWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to display some special results with AWK
# 8  
Old 09-27-2012
That's using the return value of gsub (number of substitutions made) to decide whether to print the current record. But, this will print the lines where the first field is null and has exactly 4 non-null fields (as per OP's requirement, number of non-null fields should be more than 4).

Last edited by elixir_sinari; 09-27-2012 at 03:57 AM..
# 9  
Old 09-27-2012
Quote:
Originally Posted by elixir_sinari
That's using the return value of gsub (number of substitutions made) to decide whether to print the current record. But, this will print the lines where the first field is null and has exactly 4 non-null fields (as per OP's requirement, number of non-null fields should be more than 4).
Just saw it after doing some modification to the input.
agree with you.. can be lit modified to get desired result.
i am not sure is this best way of doing it or not. just another try...Smilie

Code:
awk -F, 'gsub("[a-z0-9],","&") > 4' file

# 10  
Old 09-27-2012
Quote:
Originally Posted by pamu
Just saw it after doing some modification to the input.
agree with you.. can be lit modified to get desired result.
i am not sure is this best way of doing it or not. just another try...Smilie

Code:
awk -F, 'gsub("[a-z0-9],","&") > 4' file

That will not work correctly for non-empty last fields (and fields with uppercase and/or extended ascii characters Smilie )

Quote:
Originally Posted by vgersh99
Code:
awk -F, 'gsub(",[^,][^,]*","&") >= 4' myFile

This will not count non-empty first fields, no?

Last edited by Scrutinizer; 09-27-2012 at 05:50 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX and Linux Applications

Display mysql results nicely

Hi, perhaps this is a dumb question. I'm running queries on mysql and I'm getting tabbed results like these: mysql> SELECT * from metrics_status WHERE date = '2012-03-30'; <TABLE... (1 Reply)
Discussion started by: erick_tuk
1 Replies

2. Shell Programming and Scripting

Display find results, and pipe to xargs

I have an overnight script which runs across a large directory to repair permissions and ownership. I also have this command output the list of files affected so that cron can email these as a log file. Previously I had the command in the form: find /path/to/files -not -user myname -print -exec... (4 Replies)
Discussion started by: mij
4 Replies

3. Shell Programming and Scripting

Shell script compare all parameters in two files and display results

Hi , I am not familiar with shell programming. I have a requirement like i have two files .I need to compare the two files by comparing each parameter and i should produce 2 outputs. 1)i have around 35 parameters say i have one parameter name called db_name=dcap in one file and... (7 Replies)
Discussion started by: muraliinfy04
7 Replies

4. Shell Programming and Scripting

awk loop: display special characters

Hi everybody; I have a code and this fetches data from first.txt,modify it and outputs it to second.txt file. l awk 'NR>1 {print "l ./gcsw "$1" lt all lset Data="$2" Value "$3}' /home/gcsw/first.txt > /home/gcsw/second.txt this outputs as: l ./gcsw 123 lt all lset Data=456 Value 789 ... (1 Reply)
Discussion started by: gc_sw
1 Replies

5. Shell Programming and Scripting

Display echo results in three column

Dear Friends, I have my command output which displays on one row and values are now scrollable (vertical) 3 pages. How do i display those output in three column so that i no need to scroll? Example: dcadd$cat components 1.Caluculator 2.Diary ... ... 50.Mobile 51.Battery .. ...... (12 Replies)
Discussion started by: baluchen
12 Replies

6. Shell Programming and Scripting

need a little help with results from awk

Hi there all, I am using a line to get some replys from my PS I do ps -ef |awk '{printf $9}' But my result is 1 big line. No spaces between the lines or someting for example:... (2 Replies)
Discussion started by: draco
2 Replies

7. UNIX for Dummies Questions & Answers

Unix file does not display special characters

We have a unix file that contains special characters (ie. Ñ, °, É, ¿ , £ , ø ). When I try to read this file I get a codepage error and the characters are replaced by the # symbol. How do I keep the special characters from being read? Thanks. Ryan (3 Replies)
Discussion started by: Ryan2786
3 Replies

8. UNIX for Dummies Questions & Answers

How to display first 7 char of grep results?

My file contains the following: uat2000.aspclient.active=true uat2001.aspclient.active=true uat2002.aspclient.active=true uat2003.aspclient.active=true uat2004.aspclient.active=false uat2005.aspclient.active=false uat2006.aspclient.active=false uat2007.aspclient.active=false... (8 Replies)
Discussion started by: kthatch
8 Replies

9. Solaris

Top and Prstat display different results for memory

I have a question about the accuracy of prstat. I did a 'prstat -t' and it shows 99% of my memory is occupied by oracle. NPROC USERNAME SIZE RSS MEMORY TIME CPU 194 oracle 343G 340G 99% 86:17.24 56% However, 'top' shows I still have 7762meg of memory free. Memory: 16G real, 7762M... (4 Replies)
Discussion started by: zen03
4 Replies

10. Shell Programming and Scripting

Display special characters

I have a file that evidently has some special characters in it. Is there a Unix command that I can use tp display the file so I can see the octal or hex values? (2 Replies)
Discussion started by: BCarlson
2 Replies
Login or Register to Ask a Question