Finding reciprocal columns


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Finding reciprocal columns
# 15  
Old 02-02-2014
Hi.
Quote:
Originally Posted by wisecracker
Hi drl...
I might be missing something here but you have created two versions of the db()
function, one being a NOP, and don't seem to call either of them.
This is a template. The db functions are for debug. If one uses a debug function such as:
Code:
db "location: at the first loop"

then one can leave the line in the code and it will either be expanded as a few printf, or the very fast do-very-little command colon ( : ). This can be done simply by inter-changing the function lines. For exmaple, in vi one does ddp, and the lines are swapped.

I didn't happen to use the debug function in this script, but I leave them in there in case I wish to do some debugging later.

In more complex, production scripts, as opposed to demo scripts, one can define the functions in a fashion that might correspond to an option, say -d or --debug.

Best wishes ... cheers, drl

---------- Post updated at 16:11 ---------- Previous update was at 15:51 ----------

Hi.

More specifically, here is part of a production template that we use here:
Code:
#!/usr/bin/env bash

# @(#) s1	Production template.
# $Id: sh-production,v 1.14 2013/11/05 13:37:42 drl Exp drl $

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
#shtidyskip
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
#shtidyskip

# Short circuit for debug -- MUST BE FIRST ARGUMENT.
if [[ $# -gt 0 && "$1" =~ -de*b*u*g* ]]
then
  db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
  shift;
else
  db() { : ; }
fi

db
db "Args before getopts, n=$# :$*:"

# Set foreign to "true" if not at company.
# foreign="true" export PATH="/usr/local/bin:/usr/bin:/bin"
...

and running this with and without the debug option:
Code:
$ ./sh-production xxx

-- produces nothing, just as one might want without debugging output.
Then with debugging on:
Code:
$ ./sh-production -d xxx
 db, 
 db, Args before getopts, n=1 :xxx:
 db, Args before shift,   n=1 :xxx:
 db, Args after  shift,   n=1 :xxx:
 db, 
 db,  position - just before main file processing.
 db,  action - processing file xxx.
 db,  position - just after  main file processing.
 db,

This User Gave Thanks to drl For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Finding common entries between 10 columns

Hello, I need to find the intersection across 10 columns. Kindly help. my file (INPUT.csv) looks like this 4_R 4_S 8_R 8_S 12_R 12_S 24_R 24_S LOC_Os01g01010 LOC_Os01g01010 LOC_Os01g01010 LOC_Os04g48290 LOC_Os01g01010 LOC_Os01g01010... (1 Reply)
Discussion started by: Sanchari
1 Replies

2. Shell Programming and Scripting

Finding difference between two columns of unequal length

Hi, I have two files which look like this cat waitstate.txt 18.2 82.1 cat gostate.txt 5.6 5.8 6.1 6.3 6.6 6.9 7.2 7.5 (4 Replies)
Discussion started by: jamie_123
4 Replies

3. Shell Programming and Scripting

UNIX scripting for finding duplicates and null records in pk columns

Hi, I have a requirement.for eg: i have a text file with pipe symbol as delimiter(|) with 4 columns a,b,c,d. Here a and b are primary key columns.. i want to process that file to find the duplicates and null values are in primary key columns(a,b) . I want to write the unique records in which... (5 Replies)
Discussion started by: praveenraj.1991
5 Replies

4. Shell Programming and Scripting

Finding value bigger than zero in all columns

Hi everybody, I am a complete novice and please forgive if its answered gazillion times I have a file which looks like this 1 0 2 0 0 0 0 0 0 3 0 1 18 2 6 0 1 7 0 2 4 0 0 0 1 17 16 1 1 0 0 I have to add... (4 Replies)
Discussion started by: amits22
4 Replies

5. Shell Programming and Scripting

Finding standard deviation for all columns in a data file

Hi All, I want someone to modify the below script from this forum so that it can be used for all columns in the file( instead of only printing column 3 mean and standard deviation values). I don't know how to loop around all the columns. ... (3 Replies)
Discussion started by: ks_reddy
3 Replies

6. Shell Programming and Scripting

finding duplicates in csv based on key columns

Hi team, I have 20 columns csv files. i want to find the duplicates in that file based on the column1 column10 column4 column6 coulnn8 coulunm2 . if those columns have same values . then it should be a duplicate record. can one help me on finding the duplicates, Thanks in advance. ... (2 Replies)
Discussion started by: baskivs
2 Replies

7. Shell Programming and Scripting

Matching same columns and finding the smallest match

Hi all, I am wondering if its possible to solve my problem with a simple code. Basically I have a file that looks like this (tab delimited) bob 8 250 tina 8 225 sam 8 225 ellen 9 315 kyle 9 275 sally 9 135 So what I want to do is match columns 2 and 5. If columns 2 and 5... (2 Replies)
Discussion started by: phil_heath
2 Replies

8. Shell Programming and Scripting

finding duplicates in columns and removing lines

I am trying to figure out how to scan a file like so: 1 ralphs office","555-555-5555","ralph@mail.com","www.ralph.com 2 margies office","555-555-5555","ralph@mail.com","www.ralph.com 3 kims office","555-555-5555","kims@mail.com","www.ralph.com 4 tims... (17 Replies)
Discussion started by: totus
17 Replies

9. Shell Programming and Scripting

finding duplicate files by size and finding pattern matching and its count

Hi, I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern. Note:These are the samples of two files,but i can have more... (2 Replies)
Discussion started by: jerome Sukumar
2 Replies
Login or Register to Ask a Question