We help IT Professionals succeed at work.
Get Started

how to search a string in a variable and get part of the variable in bash

enthuguy
enthuguy asked
on
92 Views
Last Modified: 2015-10-31
HI Friends,

1. below is the sample input.txt, which I loop thru line by line using while / do loop
2. how to search a string in each line and get part of the variable and concat it

Would like to search for "asset", "description", "arg1", "arg2", "arg3", "arg4", "arg5" and get the value, then concat with name/value pair

e.g final output what I would like to have in a variable
var='asset="task1"&description="description of task1"&arg1="some arg1"&arg2="some arg2"&arg3="some arg3"&arg4="some arg4"&arg5="some arg5"'


input.txt
job_1_name=job1
job_1_asset="task1"
job_1_dependent_on="none"
job_1_status="not started"
job_1_description="description of task1"
job_1_arg1="some arg1"
job_1_arg2="some arg2
job_1_arg3="some arg3"
job_1_arg4=none
job_1_arg5=none


Pls help and thx in advance.
Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE