Solved

Split the line into multiple line based on delimeter using script

Posted on 2008-10-18
3
302 Views
Last Modified: 2013-12-26
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
Comment
Question by:sumanth_ora
  • 2
3 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
ID: 22749735

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

Open in new window

0
 

Author Comment

by:sumanth_ora
ID: 22749943
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
 
LVL 48

Expert Comment

by:Tintin
ID: 22750276
Yes, but keep in mind that >> means append to file.  If you want to create/overwrite it, use >
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now