Need help with shell commands (not sure which command is appropriate)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help with shell commands (not sure which command is appropriate)
# 8  
Old 08-21-2014
Quote:
Originally Posted by linuxUser_
Dear All,

I have 2 files namely file1 and file2.
in file1 I have something like this
Code:
Min X = -250.000000, Max X =  250.000000
Min Y = -95.000000, Max Y =  95.000000
Min Z = -95.000000, Max Z =  136.500000

I have to write this date to file2 as
Code:
xMin -250.000000;
xMax 250.000000;

yMin -95.000000;
yMax 95.000000;

zMin -95.000000;
zMax 136.500000;

xg  #calc "abs((250.000000-(-250.000000))/$level0)";
yg  #calc "abs((95.000000-(-95.000000))/$level0)";
zg  #calc "abs((136.500000-(-95.000000))/$level0)";


I hope one can easily understand what I am doing. Its all coping values and replacing previous values.

Note: files will have other entities. So echo kind of commands will not work for me.

Thanks & Regards,
linuxUser_
For the data shown in red, do you want your script to perform the arithmetic calculations shown in the comments, or do you want the comments to be part of the output with the numeric values shown replaced with data from your input file?

If your script is supposed to perform the calculations:
  1. How is your script supposed to determine the value of $level0?
  2. Is double precision floating point arithmetic sufficient for these calculations, or do you need arbitrary precision calculations rounded to six digits of precision after the decimal point?
  3. Does case matter when printing your variable names? (Your input has uppercase X, Y, and Z; your output uses lowercase x, y, and z.)
  4. Can the output lines be reordered such that xg is printed with xMin and xMax, yg is printed with yMin and yMax, and zg is printed with zMin and zMax instead of grouping all of the *g variables at the end of the output?
  5. What shell do you use? (Or more importantly, does your system have a 1993 or later version of the Korn shell? Floating point arithmetic is built-in in ksh93, but not in any other shells I use.)
This User Gave Thanks to Don Cragun For This Post:
# 9  
Old 08-21-2014
Quote:
Originally Posted by Don Cragun
For the data shown in red, do you want your script to perform the arithmetic calculations shown in the comments, or do you want the comments to be part of the output with the numeric values shown replaced with data from your input file?

If your script is supposed to perform the calculations:
  1. How is your script supposed to determine the value of $level0?
  2. Is double precision floating point arithmetic sufficient for these calculations, or do you need arbitrary precision calculations rounded to six digits of precision after the decimal point?
  3. Does case matter when printing your variable names? (Your input has uppercase X, Y, and Z; your output uses lowercase x, y, and z.)
  4. Can the output lines be reordered such that xg is printed with xMin and xMax, yg is printed with yMin and yMax, and zg is printed with zMin and zMax instead of grouping all of the *g variables at the end of the output?
  5. What shell do you use? (Or more importantly, does your system have a 1993 or later version of the Korn shell? Floating point arithmetic is built-in in ksh93, but not in any other shells I use.)
Thanks for the reply Don Cragun,

1. First of all I have posted only a portion or my code which requires data from file1 to file2 and level0 is the pre-defined integer value in my case. I have to enter some value.

2. I need arbitrary precision because precision plays a very important role in my subject.

3. I can change the input and output cases alike. Its really not matters.

4. No I want xg with xMin and xMax in this way only. Its part of calculation. Not a comment.

5. I am using bash shell environment


Thanks & Regards,
linuxUser_
# 10  
Old 08-22-2014
Quote:
Originally Posted by linuxUser_
Thanks for the reply Don Cragun,

1. First of all I have posted only a portion or my code which requires data from file1 to file2 and level0 is the pre-defined integer value in my case. I have to enter some value.

2. I need arbitrary precision because precision plays a very important role in my subject.

3. I can change the input and output cases alike. Its really not matters.

4. No I want xg with xMin and xMax in this way only. Its part of calculation. Not a comment.

5. I am using bash shell environment


Thanks & Regards,
linuxUser_
First, you have not answered Robin's question: Is this homework? If it isn't homework, where is this data coming from and how will the output be used? Without an answer to these questions, this thread will be closed.

Then, more questions based on your responses above:
1. No, you have not shown us any of your code (except for a sed command I gave you which seems to have no use in this thread, and a grep that gives you output you don't know how to process. I agree with Robin, we need to see the code you have written (even if it isn't working). And, we need to see a more representative sample of the input files this script is supposed to process. Searching for text matching a pattern in a file of arbitrarily formatted data is somewhere between hard and impossible. Searching for text in a text file where the format of all of the data in the file is well described is somewhere between easy and trivial. Make all of our lives easier by describing you input files fully.

Your first post said in file1 I have something like this
Code:
Min X = -250.000000, Max X =  250.000000
Min Y = -95.000000, Max Y =  95.000000
Min Z = -95.000000, Max Z =  136.500000

The following is something like that:
Code:
MinX = -250.000000,MaxX =  250.000000
Min y=-95.000000, Max Y =95.000000
miNz=-95.000000,maxZ=136.500000

but writing REs that recognize "something like" both of these is a much, much, more difficult task than writing an RE to match something that is "exactly" like the the first format. Are min values always negative? Are max values always non-negative? Are max values always positive?

If level0 is a "pre-defined integer value", why do you "have to enter some value"? Please explain.

2. What are you doing where getting 13 or more significant digits in the results from calculating a quotient from the sum of two input values divided by a third integer is insufficient? We can calculate arbitrary (but specified) precision results using bc or dc, but we can't print arbitrary (unspecified) precision output. (If xMin is -1, xMax is 1, and level0 is 3, your script will spend the rest of our lives printing an unending number if you insist on arbitrary precision output.) You need to clearly specify what ranges of values x, y, z, and level0 can take; and for some representative real values of those variables, show us the exact output that should be produced (not comments saying calculations should be performed) AND don't choose "nice" numbers that will produce integral results; show us real world values demonstrating the precision you need in your output. And, give a clear English description of how the precision is to be determined.

3. Maybe case doesn't matter to you, but we need to know if your script has to perform case insensitive searches for your variables in your input file and if it has to perform case translations to get the required output. We need a clear specification of what is in your input files and exactly what you want in your output file to help you write code that can find what you want in your input files and produce what you want in your output files.

4. This doesn't address the question I asked. Can the output be:
Code:
xMin -250.000000;
xMax 250.000000;
xg  result from calculating abs((250.000000-(-250.000000))/$level0);

yMin -95.000000;
yMax 95.000000;
yg  result from calculating abs((95.000000-(-95.000000))/$level0);

zMin -95.000000;
zMax 136.500000;
zg  result from calculating abs((136.500000-(-95.000000))/$level0)";

instead of the order you said you want. It will simplify your code if we can produce the x related results when we find the input line:
Code:
Min X = -250.000000, Max X =  250.000000

instead of having to save data to print at the end after finding all three significant input lines.

5. That didn't answer the question, but since you need more precision that C double-precision computation provide, it probably doesn't matter. Also, what OS are you using for this project?

And, just for fun, why is speed so important in calculating three values? Are there hundreds of input files to process? Is it the calculations that have to be fast? Or is it searching HUGE input files for your three important data lines that has to be fast? In most projects I've worked on, the speed of this part of a larger project would be insignificant unless we did some really gross stuff to slow it down unless this code will be in a loop processing lots of files.
This User Gave Thanks to Don Cragun For This Post:
# 11  
Old 08-22-2014
Dear Don Cragun,

It is not home work. I am developing a tool. It requires some automation. For automating I am using shell scripting for now.

file1 addresses the output form one of my c++ code.
file2 is part of code for another software which requires date in that format.

All I need is copying a text file and paste required values to other file in the format I specified.

1. form your questions and inputs I decides to write file1 as
Code:
minX = -250.000000;
maxX =  250.000000; minY = -95.000000;
maxY = 95.000000; minZ = -95.000000;
maxZ = 136.500000;

I guess it should be easy now to read the data?

2. Regarding precision:
All I need is a shell script that can successfully copy a number like 10.123456 or 10.12345678, it should exactly copy the number.
This plays a little important role in my application.

3. using
Code:
-i

in shell scripts is case insensitive search right? Yea your are right case really not matters.

4. Both are same. I mean it can be
Code:
 xg  #calc "abs((250.000000-(-250.000000))/$level0)";

or
Code:
xg  value;

But I would like to get 1st if it is really not difficult.

5. Linux 12.04LTS


Where speed came into picture? If ever I said speed in my previous posts, It must be related to urgency in finishing this task.
I have to copy only one file so speed really not matters.

Thanks & Regards
linuxUser_
# 12  
Old 08-26-2014
Dear Don Cragun & rbatte1,

I have solved the issue. Thanks for help Smilie.

Regards,
linuxUser_
# 13  
Old 08-26-2014
Solved it how?
# 14  
Old 08-26-2014
Quote:
Originally Posted by Corona688
Solved it how?
Dear Corona,

I taught I dont have enough time to write program in c++ but finally decided to write in cpp only. Just because of time constrains I have chosen shell, but my knowledge in shell is completely below basic.
Any way I really like this forum. People here are really helpful.
I will try to learn shell scripting also asap Smilie

Thanks & Regards,
linuxUser_
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

decipher shell commands

Hi Guys, I am busy trying to re-write a shell script that was written way back. I need help with these codes: # Process switches if ; then echo "usage : process <optional instance>" exit 99 fi What does the above code mean? What does these $? -gt 1 mean? Then I have... (3 Replies)
Discussion started by: Phuti
3 Replies

2. Shell Programming and Scripting

Any shell or hack that makes the shell command line take vi commands?

basically i'm tired of hitting the left arrow a few dozen times when correcting a mistake or modifying a history command i'd like to use vim style key shortcuts while on the command line so that a 55 moves the cursor 55 places to the left... and i want all the other vi goodies, search of... (3 Replies)
Discussion started by: marqul
3 Replies

3. UNIX for Dummies Questions & Answers

Help with shell commands

hi!i want to print all registered users(theres a difference for registered users and logged users right?we can print logged users using who command but registered?) in the system,the groups and my current running processes(with the command ps -ef , ok i can get all the running processes in the... (13 Replies)
Discussion started by: strawhatluffy
13 Replies

4. Shell Programming and Scripting

Help in shell commands

Hi, I am working on HP-AUX Unix machine. I need to find a file whether it has been updated in 15 minutes. Please help me with the command. I am using Ksh (1 Reply)
Discussion started by: chinniforu2003
1 Replies

5. Shell Programming and Scripting

Can BASH execute commands on a remote server when the commands are embedded in shell

I want to log into a remote server transfer over a new config and then backup the existing config, replace with the new config. I am not sure if I can do this with BASH scripting. I have set up password less login by adding my public key to authorized_keys file, it works. I am a little... (1 Reply)
Discussion started by: bash_in_my_head
1 Replies

6. Shell Programming and Scripting

Shell commands

Hey, I have two seperate files with a column og data about item 277 and 289 in each. Fx: 277 -1.34534 -0.98272 0.12293 etc and 289 -4.58493 9.88273 9.33829 etc. How do i get the second input for item 277 (i.e. -.098272) and add or subtract it from the similar second input from... (2 Replies)
Discussion started by: Wenani
2 Replies

7. UNIX for Dummies Questions & Answers

what are some different commands in c shell and korn shell??

I am doing this simple script using c shell and korn shell. The commands I use are fgrep , ls, and also some redirecting. Is there any difference in using both of these commands in c shell and korn shell? Thanks and sorry for the stupid question. (1 Reply)
Discussion started by: EquinoX
1 Replies

8. Shell Programming and Scripting

Hide my shell commands

I am writing a tool that connects using SSH to a remote server and perform some actions (through root) However - I would like to hide my operations so they will be hard to track. I tried STRACE on the SSHD process and saw all the traffic going there so I am quite transparent to STRACE ... (1 Reply)
Discussion started by: yamsin789
1 Replies

9. Shell Programming and Scripting

How to run unix commands in a new shell inside a shell script?

Hi , I am having one situation in which I need to run some simple unix commands after doing "chroot" command in a shell script. Which in turn creates a new shell. So scenario is that - I need to have one shell script which is ran as a part of crontab - in this shell script I need to do a... (2 Replies)
Discussion started by: hkapil
2 Replies

10. Shell Programming and Scripting

KORN Shell - Spawn new shell with commands

I want to be able to run a script on one server, that will spawn another shell which runs some commands on another server.. I have seen some code that may help - but I cant get it working as below: spawn /usr/bin/ksh send "telnet x <port_no>\r" expect "Enter command: " send "LOGIN:x:x;... (2 Replies)
Discussion started by: frustrated1
2 Replies
Login or Register to Ask a Question