Today (Saturday) We will make some minor tuning adjustments to MySQL.

You may experience 2 up to 10 seconds "glitch time" when we restart MySQL. We expect to make these adjustments around 1AM Eastern Daylight Saving Time (EDT) US.


Extract values based on parameters passing in arguments


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
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.
# 2  
Making lots of wild assumptions about what operating system (and, therefore what type of shell is installed as sh, one might try something like the following:
Code:
#!/bin/sh
IAm=${0##*/}

if [ $# -lt 2 ]
then	printf 'Usage: %s low high [low high]...\n' "$IAm" >&2
	exit 1
fi
list=$1-$2
shift 2
while [ $# -ge 2 ]
do	list=$list,$1-$2
	shift 2
done
cut -c "$list" file_name >> file_new

Obviously, you should add a check to verify that an odd number of arguments were not given and you might want to add an output pathname as a parameter instead of always appending to the file named file_new, but this should get you started.
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Extract and exclude rows based on duplicate values
CHoggarth
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...... Shell Programming and Scripting
5
Shell Programming and Scripting
Shell Script to Dynamically Extract file content based on Parameters from a pdf file
DIps
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...... Shell Programming and Scripting
3
Shell Programming and Scripting
Reading a string and passing passing arguments to a while loop
goddevil
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...... Shell Programming and Scripting
19
Shell Programming and Scripting
Passing Parameters and getting values back from a c program to Shell script
Rajeshsu
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...... Programming
5
Programming
Passing variables/arguments/parameters to commands
Perderabo
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...... Answers to Frequently Asked Questions
0
Answers to Frequently Asked Questions

Featured Tech Videos