Sponsored Content
Top Forums Shell Programming and Scripting awk - function to return permutations of n items out of m Post 303028808 by Scrutinizer on Tuesday 15th of January 2019 11:28:10 AM
Old 01-15-2019
Quote:
Originally Posted by bakunin
First of all, i am glad your problem was solved. There are still some points you might want to consider:
[..]


You definitely have a point there. As i am about to post a larger software project for the community within the next days i suggest we should have a discussion about coding standards in general. Perhaps we could all profit somewhat from such a discussion and by seeing what others do and why.

bakunin
For speed I usually start with shorter names when I create code quickly, in this case I only had a couple of minutes..
This stems from coding on the command line, where I do most of my coding. Most of the time this is for ad hoc one-time scripts. Using short variable names is a real benefit there for speed and keeping it all in the head..

If code is working well then it makes it into a more permanent script and then of course the variable names are replaced by mnemonic variable names and larded with comments (although I am definitely not a fan of overdoing comments)

In this thread it is just about coding ideas, so that one can experiment what works best, not production level solutions. They are just tiny snippets of code, quick ideas, that should be easy to understand even with minimal mnemonics. I think it may be even be a benefit as it encourages people who want to reuse the code to really think about it and try to understand the meaning .

When I am coding for production scripts, I would not dream of using single letter variables other than for counters, obviously..
For larger software projects of course, or when coding in a team this is very important, and I am all for mnemonics and coding standards, but not so much for small snippets that are just rudimentary coding ideas ...

S.
These 2 Users Gave Thanks to Scrutinizer For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Return an array of strings from user defined function in awk

Hello Friends, Is it possible to return an array from a user defined function in awk ? example: gawk ' BEGIN{} { catch_line = my_function(i) print catch_line print catch_line print catch_line } function my_function(i) { print "echo" line= "awk" line= "gawk"... (2 Replies)
Discussion started by: user_prady
2 Replies

2. Shell Programming and Scripting

Function's return value used inside awk

I have a file with the record of person: cat > $TMP/record.txt John Torres M Single 102353 Address Mark Santos M Maried 103001 Address Carla Maria F Maried 125653 Address #!/bin/ksh ManipulateID(){ ... return 0; ... #or return 1; } cat $TMP/record.txt | awk 'BEGIN {printf... (4 Replies)
Discussion started by: Orbix
4 Replies

3. Shell Programming and Scripting

awk between items including items

OS=HP-UX ksh The following works, except I want to include the <start> and <end> in the output. awk -F '<start>' 'BEGIN{RS="<end>"; OFS="\n"; ORS=""} {print $2} somefile.log' The following work in bash but not in ksh sed -n '/^<start>/,/^<end>/{/LABEL$/!p}' somefile.log (4 Replies)
Discussion started by: Ikon
4 Replies

4. Shell Programming and Scripting

Return a value from called function to the calling function

I have two scripts. script1.sh looks -------------------------------- #!/bin/bash display() { echo "Welcome to Unix" } display ----------------------------- Script2.sh #!/bin/bash sh script1.sh //simply calling script1.sh ------------------------------ (1 Reply)
Discussion started by: mvictorvijayan
1 Replies

5. Shell Programming and Scripting

awk, help me - counting items and listing them

This is my first ever post... please help! :o I have two columns....here is part of the file... 12, 46798 6692, 46799 5710, ... (3 Replies)
Discussion started by: pelhabuan
3 Replies

6. Shell Programming and Scripting

Permutations with awk

Hello I have a very simple input file in which there are a list of numbers: 1 2 3 4 5 6 7 8 9 10 My actual dataset is about 200 lines long. I was wondering how to add different permutations of 3 numbers for all the numbers in the dataset. For example: 1+2+3; 3+5+7; 2+8+1; 9+3+4... (1 Reply)
Discussion started by: Rabu
1 Replies

7. UNIX for Dummies Questions & Answers

awk colon separated items

Hi, I need to filter my data based on items in column 23. Column 1 until column 23 are tab separated. This is how column 23 looks like: PRIMARY=<0/1:504:499,5:.:.:.:0.01:1:15:.> I want to extract lines if items 7 (separated by : ) in column 23 are more than 0.25 . In example above , item... (2 Replies)
Discussion started by: janshamsani
2 Replies

8. Shell Programming and Scripting

awk permutations and combinations

hello, I'm reading this thread, in which there is this code :awk ' function comb(v,i) { for(i in A) { delete A; if(length(A)) comb((v?v"+":x)i) else print v"+"i A; } } { A } END { comb(); } ' infilebut I can't understand where does v come... (5 Replies)
Discussion started by: daPeach
5 Replies

9. Shell Programming and Scripting

Return: can only `return' from a function or sourced script

Not sure where the problem is. I can run the script without any issue using the following command. . /opt/app/scripts/cdc_migration.sh But it fails with the below error when I try it this way /opt/app/scripts/cdc_migration.sh /opt/app/scripts/cdc_migration.sh: line 65: return: can only... (1 Reply)
Discussion started by: svajhala
1 Replies

10. Shell Programming and Scripting

Function - Make your function return an exit status

Hi All, Good Day, seeking for your assistance on how to not perform my 2nd, 3rd,4th etc.. function if my 1st function is in else condition. #Body function1() { if then echo "exist" else echo "not exist" } #if not exist in function1 my all other function will not proceed.... (4 Replies)
Discussion started by: meister29
4 Replies
mconv_stream_converter(3m17n)					 The m17n Library				     mconv_stream_converter(3m17n)

NAME
mconv_stream_converter - Create a code converter bound to a stream. SYNOPSIS
MConverter* mconv_stream_converter (MSymbol name, FILE * fp) DESCRIPTION
Create a code converter bound to a stream. The mconv_stream_converter() function creates a pointer to a code converter for coding system name. The code converter is bound to stream fp. Subsequent decodings and encodings are done to/from this stream. name can be Mnil. In this case, a coding system associated with the current locale (LC_CTYPE) is used. RETURN VALUE
If the operation was successful, mconv_stream_converter() returns the created code converter. Otherwise it returns NULL and assigns an error code to the external variable merror_code. ERRORS
MERROR_SYMBOL, MERROR_CODING SEE ALSO
mconv_buffer_converter() COPYRIGHT
Copyright (C) 2001 Information-technology Promotion Agency (IPA) Copyright (C) 2001-2011 National Institute of Advanced Industrial Science and Technology (AIST) Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License <http://www.gnu.org/licenses/fdl.html>. Version 1.6.2 12 Jan 2011 mconv_stream_converter(3m17n)
All times are GMT -4. The time now is 07:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy