String parsing

Hi,

name=VDSL_TTV_  HN_SUB create coid=MA5603U phone=5678 portpolicy=APortSelectionPolicy rfu10=TTV rfu3=Dot1q sz7_portmode=VDSL2 rfu5=1234 srprofile.sy_profname=$ADSL_TTV_SubProfile1

I have a line like this. Its a single line.I need the output as
name=VDSL_TTV_ HN_SUB create
coid=coid=MA5603U
phone=5678
portpolicy=APortSelectionPolicy

the catch is that the value can also have spaces thats where i could not process. Can somebody help me on this?

The problem is you have to distinguish the whitespace inside the field value from the whitespace separating values. For example see the following:

a=foo b=bar c=foo bar d=foo

The whitespace after "c=foo" has a function different from the one after the following "bar".

I'd suggest the following rule: a space followed by a word followed by an equal sign is a field separator, otherwise it is part of a multiword field.

The downside of this is that trailing blanks will be considered part of the last field, they would have to be chopped off previous to parsing. Here is some (untested) example code (replace "<b>" and "<t>" with literal blanks/tabs):

sed s/[<b><t>]\([^<b><t>][^<b><t>]*=\)/\n\1/g /path/to/input > /path/to/output

I hope this helps.

bakunin

Hi,

something like:

sed "s/rfu.*//;s/[a-z][a-z]*=/\n&/g" file

HTH Chris

# awk -F" " '{print $1,$2,$3};{print $4};{print $5};{print $6}' infile
name=VDSL_TTV_ HN_SUB create
coid=MA5603U
phone=5678
portpolicy=APortSelectionPolicy

Hi

cat file | tr ' ' '\n' | awk 'NR!=1 && !/\=/{x=x" "$0;next;}{if(NR!=1){print x;x=$0;}else x=$0;}END{print x}'

Guru.

Thanks guys , it really works

@ ygemici :

Can you please explain your command ?

---------- Post updated at 03:54 AM ---------- Previous update was at 03:39 AM ----------

@ guruprasadpr :

can you please explain your command.

$1,$2 ... means first,second,.... patterns in our example
-F -> is set parameter for field separator actually default value is already single space so isnt neccessary if not changed more before
Fields
$1 -> name=VDSL_TTV_
$2 -> HN_SUB
$3 -> create
and we print it..:slight_smile: