Need to combine two lines in a file based on first character of each line in a file

Tags
beginners

 

 
Thread Tools Search this Thread
# 1  
Old 02-25-2016
Question Need to combine two lines in a file based on first character of each line in a file

Hi,

I have a requirement where I need to combine two lines in a file based on first character of each line in a file.

Please find the sample content of the file below:

Code:
_______________________
Code:
5, jaya, male, 4-5-90, single
smart
6, prakash, male, 5-4-84, married
fair
7, raghavi, female, 12-10-85, married
calm
talented
9, bhaskar, male, 29-12-92, single
studios

________________________

I want the output for this file as
_______________________

Code:
Code:
5, jaya, male, 4-5-90, single-smart
6, prakash, male, 5-4-84, married-fair
7, raghavi, female, 12-10-85, married-calm-talented
9, bhaskar, male, 29-12-92, single-studios

________________________

can you please help me with the shell program that achieve my requirement?

Moderator's Comments:
Mod Comment edit by bakunin: by "use CODE-tags" we didn't mean to write the word "code" but to use the tags, like the ones i edited into your text. Please use them yourself in further posts.

Last edited by bakunin; 02-25-2016 at 08:04 PM..
# 2  
Old 02-25-2016
You might find it easier to divide your problem into two separate problems which are solvable independently:

1) concatenate all lines not starting with a number to the last line starting with a number, separated by spaces.

2) replace the spaces in the last field with hyphens i.e. "word1 word2" -> "word1-word2".

What may help you is the fact that each line consists of four "fields", separated by comma. Is this only the case in your sample or is this so throughout your data?

Any efforts from your side?

I hope this helps.

bakunin
 

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Similar Threads More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Program to combine two lines in a file on checking the first character of each line jayaP Shell Programming and Scripting 12 02-26-2016 11:03 AM
Need to combine two lines in a file based on first character of each line in a file jayaP UNIX for Advanced & Expert Users 1 02-25-2016 08:49 PM
Combine lines in file mutley2202 UNIX for Dummies Questions & Answers 1 02-07-2015 12:20 PM
Joining lines in TXT file based on first character fuji_s Shell Programming and Scripting 5 08-20-2013 04:19 AM
File w/ many line pairs--how do I order based on 1st lines only? pathunkathunk Shell Programming and Scripting 1 08-03-2013 04:45 PM
Remove certain lines from file based on start of line except beginning and ending nwalsh88 Shell Programming and Scripting 10 02-20-2013 04:50 PM
Extracting lines from a text file based on another text file with line numbers evelibertine UNIX for Dummies Questions & Answers 1 12-11-2012 04:39 PM
Combine multiple unique lines from event log text file into one line, use PERL or AWK? Mayday22 Shell Programming and Scripting 3 11-06-2012 09:00 PM
Combine lines from file holyearth UNIX for Dummies Questions & Answers 4 08-12-2012 04:34 AM
Combine multiple lines in file based on specific field ratheesh2011 Shell Programming and Scripting 8 07-11-2012 03:39 PM
File character adjustment based on specific character pema.yozer Shell Programming and Scripting 1 05-29-2012 10:49 AM
join based on line number when one file is missing lines jackiev Shell Programming and Scripting 1 06-27-2011 08:08 PM
How do I combine the last 2 lines of a file jimbob75 UNIX for Dummies Questions & Answers 8 02-22-2010 04:26 AM
Combine the lines based on particular pattern VenkataPrasad Shell Programming and Scripting 3 08-26-2009 07:35 AM
Merging lines based on occurances of a particular character in a file mohan_tuty Shell Programming and Scripting 2 07-15-2008 02:14 AM
All times are GMT -4. The time now is 01:59 PM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?