Regarding the script. I need to compare two numerical values from a text file and if A<B write "1" to specific column location in the file(call this group variable). When A>B write "2" to specific column location. Every time the condition A>B is meet increment the Group value (+1).
Here is a part of the file hope this helps:
Values to be compared )in red ------------------------ Group variable (in green)
The values in red have to be compared line by line and if A<B is true write "1", once A>B is encountered increment(+1) the A<B "group value".
Is this achievable in bash script?
The way I see things and correct me if wrong.
1. Assign line 1 value from specific column to variable "A"
2. Assign line 2 value from specific column to variable "B"
3. Compare if A<B write group value of X (x =1) to specific column location.
4. if A>B X=X+1
Thanks
Moderator's Comments:
Please use code tags next time for your code and data, thanks
Not a homework assignment. So far I'm trying to figure out the best way to pass the numerical values from the text file to variables. Reading on "awk" and "sed"now. Then will look into comparing them. Also will need to figure out how to write a value to specific location.
You talk about getting A from line 1 and B from line 2.
You don't say anything about which line is supposed to receive the value X.
You don't say anything about what should happen on lines 3 through 5.
It isn't clear whether you are creating a new output field or if you are modifying data in an existing field.
The values in field 2 are monotonically increasing, but the green output field isn't always set to 1 and isn't consistently increasing.
Please describe more clearly what you are trying to do:
Please show us an input file (in CODE tags) and show us the output you want to produce from that input file (also in CODE tags).
If different things are supposed to happen when A < B than when A >= B, show us input with both cases so we can see the desired effects on the output.
If the "specific column locations" are not the constants 2 and 6, explain how you will tell your script which fields are to be processed.
Is maintaining the spacing between fields and (the inconsistent final field alignment) important?
What operating system are you using?
What shell are you using?
Concentrate on awk rather than sed for this. The sed utility is not designed to perform arithmetic (like X=X+1) nor arithmetic comparisons (like A < B).
Thank you for your replay. My logic is wrong and will need to think about this more. I will repost once I have a everything together per your criteria.
I'm new to utilities like socat and netcat and I'm not clear if they will do what I need.
I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes.
I'm using Cygwin bash on Windows 10.
My... (3 Replies)
Hello all,
I am facing a weird issue while executing a code below -
#!/bin/bash
cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset
sh UKBA_publish.sh UKBA 28082015 3
if
then
echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
I am trying to call a script(callingscript.sh) from a master script(masterscript.sh) to get string type value from calling script to master script. I have used scripts mentioned below.
#masterscript.sh
./callingscript.sh
echo $fileExist
#callingscript.sh
echo "The script is called"... (2 Replies)
I am using blow script :--
#!/bin/bash
FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not
if
then
# echo "process found"
exit 0;
else
echo "process not found"
exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Hi guys
I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file.
#!/bin/sh
echo " $2 $3 $4 $5 $6 $7
isql -w400 -U$2 -S$5 -P$3 << xxx
use $4
go
print"**Changes to the table... (0 Replies)