massage data

Hi Experts,

I do have a weird requirements.

My input data is as below.

scott;adams;unit;[2,4,6];[8,5,4];[4,5,6]
lewis;carol;min;[1,4,9];[4,0,6];[4,5,6];[0,0,0]

The required output should be like

scott;adams;unit;[2,4,6]
scott;adams;unit;[8,5,4]
scott;adams;unit;[4,5,6]
lewis;carol;min;[1,4,9]
lewis;carol;min;[4,0,6]
lewis;carol;min;[4,5,6]
lewis;carol;min;[0,0,0]

:eek::wall::confused::mad::rolleyes:
Can some one suggest a way out.

I tried the following command.

echo "[2,4,6];[8,5,4];[4,5,6]\c"|nawk '1' RS=";"
 

output
-------

[2,4,6]
[8,5,4]
[4,5,6]

Regards,
Tin-Tin

nawk -F';' '{head=($1 OFS $2 OFS $3); for(i=4;i<=NF;i++) print head,$i}' OFS=';' myFile
1 Like

Try:

awk -F\; '{x=$1 FS $2 FS $3;for (i=4;i<=NF;i++){print x FS $i}}' input_file
1 Like

Thank You all for the concerns. I have been a regular follower, but a novice thread creator. Sorry for the Trouble.

Experts, But can the code be modified so as to manage any number of columns other than the first 3 in any line ? Here the loop is limited to '4'.

Regards,
Tinu Farid

---------- Post updated at 02:25 AM ---------- Previous update was at 02:21 AM ----------

Sorry the result is perfect..:cool: