I was trying a shell script. I was unable to store file contents to a variable in the script. I have tried the below but unable to do it.
Input = `cat /path/op.diary`
Input = $(<op.diary)
I am using ksh shell. I want to store the 'op.diary' file contents to the variable 'Input' and i want to use some other commands later on the variable 'Input'.
Not sure about your complete requirement but storing whole file's content into a single variable doesn't seems to be a good method, in spite of that you could read a file line by line by using while loop or you could use awk, sed to accomplish your requirements, if you have any queries please do let us know complete requirement with sample Input_file and expected output, hope this helps.
Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
Thanks for your reply. I have tried it using
loop as below but did not get the result.
My input file looks like below. I am giving a few lines of it. Original file contains 210 lines.
After storing the file contents to a variable , I want to use grep command to remove some of the records in field 2 and then i want to append some other file to the resulting file.
When i am asking the user to enter the file manually and read the file with the
command, i am able to do it but when i am trying the script to read itself,can not able to do.
Please let me know your thoughts on this.
Thanks in advance.
---------- Post updated at 08:07 AM ---------- Previous update was at 08:02 AM ----------
One more thing i would like you to know that i did not try using awk or sed as i do not know how to use them for this purpose.
Thanks for your reply. I just want to make the shell script to read the file on its own instead of manually entering input. Below is how my sample file looks like. I want to store it in a variable say 'Input'.
Please let me know if you need any other information.
You haven't shown the expected output or your aim for writing the script(you have mentioned same thing of storing the Input_file's line into a variable which you told into very first post.). Putting a very wild guess like you wanted to print field 2 of each line, following may help you in same the.
Output will be as follows.
Please get back to me in case any queries with complete details of your requirement with samples please.
am24, do you see a syntax error when you use the commands in your first post or what does "unable to do it" mean?
When you asign a value to a variable there are no spaces allowed around the equal sign, no matter where the content of the variable came from.
At least this should work unless you hit some size limit:
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)