• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 334
  • Last Modified:

Split the line into multiple line based on delimeter using script

Input file

xxx,yyy,zzz,1
vvv,mmm,ppp,bbb,lll,3
jjj,rrr,4


I need the following utput
xxx,1
yyy,1
zzz,1
vvv,3
mmm,3
ppp,3
bbb,3
lll,3
jjj,4
rrr,4

Need to split each line into multiple lines based on delimeter , except last column .Last column shoud append to each spillted line

0
sumanth_ora
Asked:
sumanth_ora
  • 2
1 Solution
 
TintinCommented:

awk -F, '{for (i=1; i<NF; i++) printf "%s,%d\n",$i,$NF}' file

Open in new window

0
 
sumanth_oraAuthor Commented:
here we need to rea from file1 & shoul write to file2

Can we modify like this


 awk -F, '{for (i=1; i<NF; i++) printf "%s,%d\n",$i,$NF}' file1 >> file2
 
0
 
TintinCommented:
Yes, but keep in mind that >> means append to file.  If you want to create/overwrite it, use >
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now