[Shell script] How to read, filter and split from text file
Hi all,
First, I am sorry if my question duplicate with someone before. Second, I am trying to create a shell script which will read a text file and give me information from text file. Example: $cat abc.txt android_1=/home/abc/xyz/source/android kernel_1=/home/abc/xyz/source/android/kernel/board1 ... ... and so on I want to create shell script which get directory information from abc.txt such as return "/home/abc/xyz/source/android" How can I do that, any one help me please.... Too many thanks. |
I solved this problem.
Use: grep "kernel_1" abc.txt | awk -F "=" '{print $2}' |
There are lots of ways of doing this. For your solution, there is no need for grep - awk can do the match and print when found. Saves shelling out to grep to read the whole file then read the grep output with awk.
Could also be done entirely in bash with parameter substitution. |
If your whole file looks like the example, you could also simply source the file and use the variables from the file:
Code:
source abc.txt |
Thank all you very much for your help.
I will try with your recommendation. Have a nice day. Tee. |
All times are GMT -5. The time now is 08:14 PM. |