Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Split the line into multiple line based on delimeter using script

Posted on 2008-10-18
3
Medium Priority
?
329 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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Suggested Courses

972 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