Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Extract values based on parameters passing in arguments Post 303036251 by Jairaj on Thursday 20th of June 2019 08:43:31 PM
Old 06-20-2019
Extract values based on parameters passing in arguments

Based on arguments passing in command prompt values should fetch and store in new file.

Sample:-

Code:
sh test.sh 10 30 35 45

cat test.sh
..

cut -c $1-$2,$3-$4 file_name >> file_new
...
...

Above sample passing 4 arguments.. but it may differ (sh test.sh 10 30 35 45 70 75 ) based on arguments to fetch without changing scripts.
 

10 More Discussions You Might Find Interesting

1. Answers to Frequently Asked Questions

Passing variables/arguments/parameters to commands

A good place to start is simple variable passing.... Passing variables from one script to another The next level is passing a variable into a more complex command such as using a variable in a sed command. There are some simple quoting techniques that are very general. These are mentioned... (0 Replies)
Discussion started by: Perderabo
0 Replies

2. Programming

Passing Parameters and getting values back from a c program to Shell script

I am having a shell script which has to be called from a C program. I have to pass two parameters to this script. HOw can I do that? eg: int main() { char st1; char str2; // call a shell script call_sh(str1,str2) where call_sh is the name of the shell script. then i need to get the return... (5 Replies)
Discussion started by: Rajeshsu
5 Replies

3. Shell Programming and Scripting

passing more than 9 parameters

hi, i am passing around 14 parameters for a script a=$1 b=$2 c=$3 d=$4 e=$5 f=$6 g=$7 h=$8 i=\"${9}\" shift j=\"${1}\" still for j it is displaying the 1st parameter value..how to make it take the 10th parameter (2 Replies)
Discussion started by: dnat
2 Replies

4. Shell Programming and Scripting

extract from a file based on values in another file

Hello, I have two files that have delimited entries as shown below. I would like to use either Perl or Shell script to extract all the rows in File 1 corresponding to values in File 2 and output it to another File. File 1 ------- 1 36 24 Object1 2 45 36 Object2 3 96 ... (1 Reply)
Discussion started by: Gussifinknottle
1 Replies

5. Shell Programming and Scripting

tar cmd how many arguments into parameters of filenames

Hi I would like to use tar cmd in my script. I have a variable with filenames, e.g. 1000 records and I would like to paste its values into tar cmd. For this example I used three elements variable strings. strings="file1.txt file2.txt file3.txt" `tar cf file1.tar $strings` Whether... (1 Reply)
Discussion started by: presul
1 Replies

6. Shell Programming and Scripting

Optional Parameters/arguments while executing a script.

Hello, I have a shell script "Test.ksh" and I need to pass 8 parameters/arguments while executing the script ./Test.ksh 1 2 3 4 5 6 7 8 Out of these I want first 3 to be compulsory and rest 5 to be optional. Can you suggest the way to do this like and also how to pass these optional... (3 Replies)
Discussion started by: indrajit_u
3 Replies

7. Shell Programming and Scripting

Reading a string and passing passing arguments to a while loop

I have an for loop that reads the following file cat param.cfg val1:env1:opt1 val2:env2:opt2 val3:env3:opt3 val4:env4:opt4 . . The for loop extracts the each line of the file so that at any one point, the value of i is val1:env1:opt1 etc... I would like to extract each... (19 Replies)
Discussion started by: goddevil
19 Replies

8. Shell Programming and Scripting

Shell Script to Dynamically Extract file content based on Parameters from a pdf file

Hi Guru's, I am new to shell scripting. I have a unique requirement: The system generates a single pdf(/tmp/ABC.pdf) file with Invoices for Multiple Customers, the format is something like this: Page1 >> Customer 1 >>Invoice1 + invoice 2 >> Page1 end Page2 >> Customer 2 >>Invoice 3 + Invoice 4... (3 Replies)
Discussion started by: DIps
3 Replies

9. Shell Programming and Scripting

Extract and exclude rows based on duplicate values

Hello I have a file like this: > cat examplefile ghi|NN603762|eee mno|NN607265|ttt pqr|NN613879|yyy stu|NN615002|uuu jkl|NN607265|rrr vwx|NN615002|iii yzA|NN618555|ooo def|NN190486|www BCD|NN628717|ppp abc|NN190486|qqq EFG|NN628717|aaa HIJ|NN628717|sss > I can sort the file by... (5 Replies)
Discussion started by: CHoggarth
5 Replies

10. UNIX for Beginners Questions & Answers

Positional Parameters Arguments/Variables when using dot (.)

Hi, Is there a special positional variables for when using the dot (.)? Scripts are as below: $: head -100 x.ksh /tmp/y.ksh ==> x.ksh <== #!/bin/ksh # . /tmp/y.ksh 1234 abcd echo "yvar1 = $yvar1" echo "yvar2 = $yvar2" ==> /tmp/y.ksh <== #!/bin/ksh (2 Replies)
Discussion started by: newbie_01
2 Replies
PY.TEST(1)							      pytest								PY.TEST(1)

NAME
pytest - pytest usage CALLING PY.TEST THROUGH PYTHON -M PY.TEST New in version 2.0. If you use Python-2.5 or later you can invoke testing through the Python interpreter from the command line: python -m pytest [...] This is equivalent to invoking the command line script py.test [...] directly. GETTING HELP ON VERSION, OPTION NAMES, ENVIRONMENT VARIABLES py.test --version # shows where pytest was imported from py.test --funcargs # show available builtin function arguments py.test -h | --help # show help on command line and config file options STOPPING AFTER THE FIRST (OR N) FAILURES To stop the testing process after the first (N) failures: py.test -x # stop after first failure py.test --maxfail=2 # stop after two failures SPECIFYING TESTS
/ SELECTING TESTS Several test run options: py.test test_mod.py # run tests in module py.test somepath # run all tests below path py.test -k string # only run tests whose names contain a string Import 'pkg' and use its filesystem location to find and run tests: py.test --pyargs pkg # run all tests found below directory of pypkg MODIFYING PYTHON TRACEBACK PRINTING
Examples for modifying traceback printing: py.test --showlocals # show local variables in tracebacks py.test -l # show local variables (shortcut) py.test --tb=long # the default informative traceback formatting py.test --tb=native # the Python standard library formatting py.test --tb=short # a shorter traceback format py.test --tb=line # only one line per failure DROPPING TO PDB (PYTHON DEBUGGER) ON FAILURES Python comes with a builtin Python debugger called PDB. py.test allows one to drop into the PDB prompt via a command line option: py.test --pdb This will invoke the Python debugger on every failure. Often you might only want to do this for the first failing test to understand a certain failure situation: py.test -x --pdb # drop to PDB on first failure, then end test session py.test --pdb --maxfail=3 # drop to PDB for the first three failures SETTING A BREAKPOINT
/ AKA SET_TRACE() If you want to set a breakpoint and enter the pdb.set_trace() you can use a helper: import pytest def test_function(): ... pytest.set_trace() # invoke PDB debugger and tracing In previous versions you could only enter PDB tracing if you disabled capturing on the command line via py.test -s. PROFILING TEST EXECUTION DURATION
To get a list of the slowest 10 test durations: py.test --durations=10 CREATING JUNITXML FORMAT FILES
To create result files which can be read by Hudson or other Continuous integration servers, use this invocation: py.test --junitxml=path to create an XML file at path. CREATING RESULTLOG FORMAT FILES
To create plain-text machine-readable result files you can issue: py.test --resultlog=path and look at the content at the path location. Such files are used e.g. by the PyPy-test web page to show test results over several revi- sions. SENDING TEST REPORT TO POCOO PASTEBIN SERVICE
Creating a URL for each test failure: py.test --pastebin=failed This will submit test run information to a remote Paste service and provide a URL for each failure. You may select tests as usual or add for example -x if you only want to send one particular failure. Creating a URL for a whole test session log: py.test --pastebin=all Currently only pasting to the http://paste.pocoo.org service is implemented. CALLING PY.TEST FROM PYTHON CODE New in version 2.0. You can invoke py.test from Python code directly: pytest.main() this acts as if you would call "py.test" from the command line. It will not raise SystemExit but return the exitcode instead. You can pass in options and arguments: pytest.main(['x', 'mytestdir']) or pass in a string: pytest.main("-x mytestdir") You can specify additional plugins to pytest.main: # content of myinvoke.py import pytest class MyPlugin: def pytest_addoption(self, parser): raise pytest.UsageError("hi from our plugin") pytest.main(plugins=[MyPlugin()]) Running it will exit quickly: $ python myinvoke.py ERROR: hi from our plugin AUTHOR
holger krekel at merlinux eu COPYRIGHT
2011, holger krekel et alii 2.2 June 24, 2012 PY.TEST(1)
All times are GMT -4. The time now is 03:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy