Issue
I want to write a shell script that will parse each line of an input text file and give me output in format of key-value.
NAME=Bhavin,RollNo=123,Class=10,Rank=1 ( Line 1 )
EMPLOYEE=Prashant,EID=233,Role=Consultant ( Line 2 )
COMPANY=xyz,location=india ( Line 3 )
The expected Output is :
Name = Bhavin
RollNo = 123
Class = 10
Rank = 1
**********
EMPLOYEE=Prashant
EID=233
Role=Consultant
**********
COMPANY=xyz
location=india
**********
Thanks , Bhavin
Solution
Using awk you can do:
awk -F '[ ,]+' '{for (i=1; i<=NF; i++) if (index($i, "=")) {
split($i, a, "="); print a[1], "=", a[2]} print "**********"}' file
NAME = Bhavin
RollNo = 123
Class = 10
Rank = 1
**********
EMPLOYEE = Prashant
EID = 233
Role = Consultant
**********
COMPANY = xyz
location = india
**********
Answered By - anubhava Answer Checked By - David Marino (WPSolving Volunteer)