I have a few to questions pose in response first:-
Is this homework/assignment? There are specific forums for these.
What have you tried so far?
What output/errors do you get?
Are you needing the answer in the last few rows to be calculated to give an answer? ... and where does $level0 come from?
What OS and version are you using?
What are your preferred tools? (C, shell, perl, awk, etc.)
What logical process have you considered? (to help steer us to follow what you are trying to achieve)
Most importantly, What have you tried so far?
There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.
We're all here to learn and getting the relevant information will help us all.
Thanks for the reply.
To be specific, I want to do all there operations using shell script.
I am using linux 12.04 LTS.
Things I tried so far.
1. I know how to read complete file as variable. This can be done by simple shell script as follows
now readFile is a variable having all the information in specified file. to confirm one can check as follows
This will print complete file contents.
2. If I know the value of a variable to replace, I can do somthing like this
(Thanks to Don Cragun for the above code)
3. I don't know how to read particular value. Only thing I know is the variable names I wanted to read from file.
As specifies in my thread
...
to read this I can get whole line using grep command as follows
will get complete line
called
So, All I need now is how to read a particular value from the file and store in some variable and write it to new file.
It's good to see what you have got already. Will the input always be in this fixed format? i.e. two labels, equals, value, comma, two labels, equals, value
If it's always three lines, then we can work with that. Would you like something fast, or something easy to read?
Yes, Input is always in the same format.
But the values can be anu real numbers.
As of now I need something very fast. I would like to know if any easy ways available as well.
So for fast, I presume you are reading many files in, so perhaps someone can consider that with a good awk command.
For a relatively simple but probably slow ksh/bash script, you could try:-
That will give you the values, so you can write the first rows of the output. You will then have to calculate the results and write the last records too.
By way of explanation:-
The sed is getting the line number referenced as x in -n xp
The read has place holders a-f to ignore some of the record
The minx="${minx%,}" etc. trims the trailing comma off the string.
You can get the ABS value by the using the last trick with a different format. You would use:-
... to trim off a leading hyphen. Now the floating point calculation might be a bit trickier.
There is surely an awk function to do this all in one, but I'm not very experienced in it. If someone else would like to offer something, I will not be upset, but I will have a think.
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)