Well, now we have got the input file. I have to second RavinderSingh13 saying that it's highly improbable you want store that file's contents into a shell variable (as a final goal). What do you want to do with those data? Please show the final output (as a sample) and the logics (conditions, algorithms) that connect both.
I just want to read the input file by using any code inside the shell script so that the script automatically reads the file and store it in a variable.
As of now i have followed the below in my shell script.
I need to read six different files and apply some grep and cat and sort commands. So instead of asking the user to enter six files manually, i want the script to read the file from the path when it executed.
Is there any way to read the input file instead of the way i used in the script ?
Hope i am clear on my specifications.
Thanks in advance.
---------- Post updated at 09:49 AM ---------- Previous update was at 09:44 AM ----------
Hi Ravindhar,
I am sorry, may be i am not clear on my specifications.
Below is the script which i wrote.
In the above, i am reading the input by asking user to enter manually when running the shell script. Instead of that, i want the shell script to read the Input file from the path and store it in a variable 'Input1' .
By using the while loop or Input1 = `cat /path/filename/`, i am unable to do it. I am getting a message "Input1 not found" .
Like the above , i have to read six different files and execute same grep and cat commands. So i want to put all of the code in one shell script. Instead of asking user manually to enter six times six different input files, i want the script to read it on its own.
Hope i am clear this time.
Please let me know if you need further any more information.
If I got your requirement exactly, following may help you in same then.
You could add your files as above mentioned into your script and let us know how it goes. Also for using while loop you could try that too as follows.
Hope this helps you.
Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
The original input file contains values for these 14 markets and I want to make all those values to '0.000' . So I am grepping out the 14 markets mentioned in script(514,519 etc) from the input file and appending the CR file to the resulting file and then sorting the final resulting file.
The CR file contains the '0.000' values for all the 14 market and it looks like below.
You want to store something in a variable. What are you going to do with that variable? Leave it sitting there until you quit the session?
You have six input files. Do you want to loop across those? Do you have the files' names in another file to be read in the loop? I can't see the difference (nor identity) between "input file" in post#1 and in post#9.
Please take a step back, start over and rephrase your spec in plain English, supplying input data (obv. already given), control file, final output (as a sample) and the logics (conditions, algorithms) that connect both.
Thanks for suggestions. I will try it out and let you know the results.
---------- Post updated 04-15-16 at 02:06 AM ---------- Previous update was 04-14-16 at 10:04 AM ----------
Hi Ravindhar,
I have tried the code as you suggested and the below is working.
Input1="/tmp/chumma_file"
I also tried with while loop. But it did not work.
However i have proceeded with the first Scenario . Thank you so much for your time and suggestions on this :-)
Hi Cero,
Thanks for your suggestion. I have tried the below code which you suggested but it did not work.
Input1=`cat /path/op.diary`
So I have proceeded with the code which Ravindhar suggested.
Hi Rudi,
Thanks for your time on this. Unfortunately i am not clear on my specifications to you. But thanks a lot for looking into this. As mentioned above i have proceeded with the code which Ravindhar suggested and it worked fine.
In the below bash I am trying to read each file from a specific directory into a variable REF or VAL. Then use those variables in an awk to compare each matching file from REF and VAL. The filenames in the REF are different then in the VAL, but have a common id up until the _ I know the awk portion... (15 Replies)
I have a below syntax its working fine...
var12=$(ps -ef | grep apache | awk '{print $2,$4}')
Im getting expected output as below:
printf "%b\n" "${VAR12}"
dell 123
dell 456
dell 457
Now I wrote a while loop.. the output of VAR12 should be passed as input parameters to while loop and results... (5 Replies)
I am working on a script for Mac OS X that, among many other things, gets a list of all the installed Applications. I am pulling the list from the system_profiler command and formatting it using grep and awk. The problem is that I want to be able to use each result individually later in the script.... (3 Replies)
Hi one of the output of the command is as below
# sed -n "/CCM-ResourceHealthCheck:/,/---------/{/CCM-ResourceHealthCheck:/d;/---------/d;p;}" Automation.OutputZ$zoneCounter | sed 's/$/<br>/'
Resource List : <br>
*************************** 1. row ***************************<br>
... (2 Replies)
Hi all, im having snags creating a variable which uses commands like cut and grep. In the instance below im simply trying to take a value from another file and assign it to a variable. When i do this it only prints the $a rather than the actual value. I know its simple but does anyone have any... (1 Reply)
i want to store the output of 'tail -5000 file' to a variable.
If i want to access the contents of that variable, it becomes kinda difficult because when the data is stored in the variable, everything is mushed together. you dont know where a line begins or ends.
so my question is, how can i... (3 Replies)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
I have to read the contents of each field of a file creating user accounts.
The file will be of format :
... (6 Replies)
My file is in this format :
username : student information : default shell : student ID
Eg :
joeb:Joe Bennett:/bin/csh:1234
jerryd:Jerry Daniels:/bin/csh:2345
deaverm: Deaver Michelle:/bin/bash:4356
joseyg:Josey Guerra:/bin/bash:8767
michaelh:Michael Hall:/bin/ksh:1547
I have to... (1 Reply)
Hi folks,
I'm using bash and would like to do the following. I would like to read some values from the file and store it in the variable and use it.
My file is 1.txt and its contents are
VERSION=5.6
UPDATE=4
I would like to read "5.6" and "4" and store it in a variable in shell... (6 Replies)