Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Join lines based on regular expression 1

Status
Not open for further replies.

sunixadm

Technical User
Sep 20, 2001
73
DE
Hi all,

I have a file with data that looks like this
CUSTID3478901
pono1 9876534
pono2 6345827
pono3 4567001

CUSTID7650943
pono1 0192835
pono2 6019834
pono3 8876123
pono4 9933457
pono5 7756382
pono6 8566123

The list contains thousands of "CUSTID"s and each CUSTID can have anywhere from 0 to 12 "pono"s.

I need the output to look like:
CUSTID7650943, pono1 0192835, pono2 6019834, pono3 8876123, pono4 9933457, pono5 7756382, pono6 8566123

So to summarize; Match on REGEXP CUSTID, join all following lines, seperated by a comma (,) regardless of number of following lines until REGEXP is matched again and then, start new line starting with REGEXP and join all following lines, seperated by a comma (,) regardless of number of following lines.... until the end of the file is reached.

Thanks in advanced for your responses.
-Joe
 
Thanks feherke,

I haven't been using perl long and had never seen the -p option. Your recommendation works like a charm.
-joe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top