Python/Perl/Shell ??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Python/Perl/Shell ??
# 1  
Old 04-13-2016
Python/Perl/Shell ??

Hi All,

I'm confused what to use (Python/Perl/Shell), I have a scenario here wherein i need to process a data which might have millions of records in tabular format, my task is to find the {0,null,NA} in each and every column and also inform the end user that this column has this many values accumulated.

for ex :-

Code:
Code:
id	name 	desc
1	Raj	null
2	Nick	NA
0	Digu	fine with it
3	NA	go ahead
4	Duvi	baby


So in above table id has only 0 occuring only once so the ratio would be 80%, similarly name has NA only once it also has ratio of 80% and desc column has both (NA,null). So the ratio would be 60%.

O/P should tell the name of the column along with the ratio.

PS : The data may be millions of records, so we are concerned about time complexity
# 2  
Old 04-13-2016
not sure. try:
Code:
awk  '
NR==1 {for (cc=1; cc<=NF; cc++) n[$cc]=$cc; t=$0; next;}
{
   if ($1 != "0") c[1]++;
   for (i=2; i<=NF; i++) if ($i != "NA" && $i != "null" ) c[i]++;
}
END {
   print t;
   --NR
   r="";
   for (i=1 ; i<cc; i++) {
      p=(c[i]/NR)*100;
      r=(i == 1) ? "" p : r OFS p;
   }
   print r
}
' FS="\t" OFS="\t" infile

This User Gave Thanks to rdrtx1 For This Post:
# 3  
Old 04-14-2016
thanks for the solution, but i forgot to mention that my delimiter here is "|" symbol.
How do i proceed?

I got the solution, just changed the

Code:
Code:
FS="|" OFS="|" infile


Last edited by nikhil jain; 04-14-2016 at 03:39 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting shell to Perl I run into shell built in function trap and need alternative in Perl

I am working on converting shell to Perl script. In shell we have built in function trap Do you know alternative in Perl or actually we don't need it? Thanks for contribution (3 Replies)
Discussion started by: digioleg54
3 Replies

2. Shell Programming and Scripting

Compare and contrast Perl v Python

Anyone care to give me the cliff notes as to why one would want to use perl vs python? Unix Solaris over here. Have capability to run both perl and python and bash/ksh and others. Now what I am interested in using unix and its programs for large amounts of data, sql (done in Unix SAS)...etc.... (5 Replies)
Discussion started by: sas
5 Replies

3. Shell Programming and Scripting

conversion of code in perl and python

How to convert below bash code in perl and python. for BLOCK in /sys/block/emcpow* do echo "100000" > "$BLOCK"/queue/nr_requests echo "noop" > "$BLOCK"/queue/scheduler done (2 Replies)
Discussion started by: learnbash
2 Replies

4. Shell Programming and Scripting

perl, python, or ? for a particular task

I have a client that needs some data downloaded from a website periodically. The problem is that the data is not available directly (i.e. ftp) and must be accessed via logging in to the site, selecting the data manually, then finally clicking a link to grab the zip file. The site does not have an... (2 Replies)
Discussion started by: shunk wugga
2 Replies

5. Programming

Python: bash-shell-like less functionality in the python shell

Hello, Is there some type of functional way to read things in the Python shell interpreter similar to less or more in the bash (and other) command line shells? Example: >>> import subprocess >>> help(subprocess) ... ... I'm hoping so as I hate scrolling and love how less works with... (0 Replies)
Discussion started by: Narnie
0 Replies

6. Shell Programming and Scripting

Perl Vs Python

Hello all, I am in a bit of dilema here. I want to implement a suite. it involves a lot of text file processing and shell scripts . which one to use perl or python ? (4 Replies)
Discussion started by: achak01
4 Replies

7. Homework & Coursework Questions

Help with Simple Perl/Python Script

I have the following problem, which I need done in Perl/ or Python using Unix/linux filters... 1. You have a very large file, named 'ColCheckMe', tab-delmited, that you are asked to process. You are told that each line in 'ColCheckMe' has 7 columns, and that the values... (1 Reply)
Discussion started by: Swapnilsagarwal
1 Replies

8. Shell Programming and Scripting

Help with Simple Perl/Python Script

I have the following problem, which I need done in Perl/ or Python using Unix/linux filters... 1. You have a very large file, named 'ColCheckMe', tab-delmited, that you are asked to process. You are told that each line in 'ColCheckMe' has 7 columns, and that the values in the... (1 Reply)
Discussion started by: Swapnilsagarwal
1 Replies

9. Shell Programming and Scripting

Perl to Python

Friends How to convert this perl notation to Python ${$$hashptr{$sys_Id}}{$doc_Id} = $docstr; Jagan (0 Replies)
Discussion started by: jaganadh
0 Replies

10. Shell Programming and Scripting

Perl style i++ in Python

friends Is it possible to implement perl style autoincriment in python? e.g i++ How it can be represented in python Jagan (1 Reply)
Discussion started by: jaganadh
1 Replies
Login or Register to Ask a Question