Sponsored Content
Top Forums Shell Programming and Scripting awk - function to return permutations of n items out of m Post 303028515 by nezabudka on Thursday 10th of January 2019 12:51:58 AM
Old 01-10-2019
Quote:
Originally Posted by wisecracker
Can this be any simpler?
Single statement, longhand, OSX 10.14.1, default bash shell...
Code:
Last login: Wed Jan  9 23:14:09 on ttys000
AMIGA:amiga~> echo $'\n'{a..e}$' '{a..e}$' '{a..e}
AMIGA:amiga~> _

It's really very short!
Code:
eval echo "$'\n'{$var1..$var2}$' '{$var1..$var2}"

 

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
QAxScript(3qt)															    QAxScript(3qt)

NAME
QAxScript - Wrapper around script code SYNOPSIS
This class is part of the Qt ActiveQt Extension. #include <qaxscript.h> Inherits QObject. Public Members enum FunctionFlags { FunctionNames = 0, FunctionSignatures } QAxScript ( const QString & name, QAxScriptManager * manager ) ~QAxScript () bool load ( const QString & code, const QString & language = QString::null ) QStringList functions ( FunctionFlags flags = FunctionNames ) const QString scriptCode () const QString scriptName () const QAxScriptEngine * scriptEngine () const QVariant call ( const QString & function, const QVariant & var1 = QVariant ( ), const QVariant & var2 = QVariant ( ), const QVariant & var3 = QVariant ( ), const QVariant & var4 = QVariant ( ), const QVariant & var5 = QVariant ( ), const QVariant & var6 = QVariant ( ), const QVariant & var7 = QVariant ( ), const QVariant & var8 = QVariant ( ) ) QVariant call ( const QString & function, QValueList<QVariant> & arguments ) Signals void entered () void finished () void finished ( const QVariant & result ) void finished ( int code, const QString & source, const QString & description, const QString & help ) void stateChanged ( int state ) void error ( int code, const QString & description, int sourcePosition, const QString & sourceText ) DESCRIPTION
This class is defined in the Qt ActiveQt Extension, which can be found in the qt/extensions directory. It is not included in the main Qt API. The QAxScript class provides a wrapper around script code. Every instance of the QAxScript class represents a piece of scripting code in a particular scripting language. The code is loaded into the script engine using load(). Functions declared in the code can be called using call(). The script provides scriptEngine() provides feedback to the application through signals. The most important signal is the error() signal. Direct access to the QAxScriptEngine is provided through the scriptEngine() function. Warning: This class is not available with the bcc5.5 and MingW compilers. Member Type Documentation QAxScript::FunctionFlags This FunctionFlags enum describes formatting for function introspection. QAxScript::FunctionNames - Only function names are returned. QAxScript::FunctionSignatures - Returns the functions with signatures. MEMBER FUNCTION DOCUMENTATION
QAxScript::QAxScript ( const QString & name, QAxScriptManager * manager ) Constructs a QAxScript object called name and registers it with the QAxScriptManager manager. This is usually done by the QAxScriptManager class when loading a script. A script should always have a name. A manager is necessary to allow the script code to reference objects in the application. The manager takes ownership of the object. QAxScript::~QAxScript () Destroys the object, releasing all allocated resources. QVariant QAxScript::call ( const QString & function, const QVariant & var1 = QVariant ( ), const QVariant & var2 = QVariant ( ), const QVariant & var3 = QVariant ( ), const QVariant & var4 = QVariant ( ), const QVariant & var5 = QVariant ( ), const QVariant & var6 = QVariant ( ), const QVariant & var7 = QVariant ( ), const QVariant & var8 = QVariant ( ) ) Calls function, passing the parameters var1, var1, var2, var3, var4, var5, var6, var7 and var8 as arguments and returns the value returned by the function, or an invalid QVariant if the function does not return a value or when the function call failed. See QAxScriptManager::call() for more information about how to call script functions. QVariant QAxScript::call ( const QString & function, QValueList<QVariant> & arguments ) This is an overloaded member function, provided for convenience. It behaves essentially like the above function. Calls function passing arguments as parameters, and returns the result. Returns when the script's execution has finished. See QAxScriptManager::call() for more information about how to call script functions. void QAxScript::entered () [signal] This signal is emitted when a script engine has started executing code. void QAxScript::error ( int code, const QString & description, int sourcePosition, const QString & sourceText ) [signal] This signal is emitted when an execution error occured while running a script. code, description, sourcePosition and sourceText contain information about the execution error. void QAxScript::finished () [signal] This signal is emitted when a script engine has finished executing code. void QAxScript::finished ( const QVariant & result ) [signal] This is an overloaded member function, provided for convenience. It behaves essentially like the above function. result contains the script's result. This will be an invalid QVariant if the script has no return value. void QAxScript::finished ( int code, const QString & source, const QString & description, const QString & help ) [signal] This is an overloaded member function, provided for convenience. It behaves essentially like the above function. code, source, description and help contain exception information when the script terminated. QStringList QAxScript::functions ( FunctionFlags flags = FunctionNames ) const Returns a list of all the functions in this script if the respective script engine supports introspection; otherwise returns an empty list. The functions are either provided with full prototypes or only as names, depending on the value of flags. See also QAxScriptEngine::hasIntrospection(). bool QAxScript::load ( const QString & code, const QString & language = QString::null ) Loads the script source code written in language language into the script engine. Returns TRUE if code was successfully entered into the script engine; otherwise returns FALSE. If language is empty (the default) it will be determined heuristically. If code contains the string End Sub it will be interpreted as VBScript, otherwise as JScript. Additional scripting languages can be registered using QAxScript::registerEngine(). This function can only be called once for each QAxScript object, which is done automatically when using QAxScriptManager::load(). QString QAxScript::scriptCode () const Returns the script's code, or the null-string if no code has been loaded yet. See also load(). QAxScriptEngine * QAxScript::scriptEngine () const Returns a pointer to the script engine. You can use the object returned to connect signals to the script functions, or to access the script engine directly. QString QAxScript::scriptName () const Returns the name of the script. void QAxScript::stateChanged ( int state ) [signal] This signal is emitted when a script engine changes state. state can be any value in the QAxScriptEngineState enumeration. SEE ALSO
http://doc.trolltech.com/qaxscript.html http://www.trolltech.com/faq/tech.html COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement. AUTHOR
Generated automatically from the source code. BUGS
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech. If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qaxscript.3qt) and the Qt version (3.3.8). Trolltech AS 2 February 2007 QAxScript(3qt)
All times are GMT -4. The time now is 05:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy