Solved

Split the line into multiple line based on delimeter using script

Posted on 2008-10-18
3
316 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

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 …
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

738 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