Sponsored Content
Top Forums Shell Programming and Scripting Script to combine lines in a file Post 302996429 by rnnyusa on Wednesday 26th of April 2017 07:08:17 AM
Old 04-26-2017
Script to combine lines in a file

Greetings,
I have large file with following format

Code:
name1 name2
name3 name4
name5 name6
 child7 child8 child9                      <== there is leading blank space
 child10 child11 child12                 <== there is leading blank space
name13 name14
name15 name16
 child17 child18 child19                 <== there is leading blank space
name20 name21
 child22 child23 child24                 <== there is leading blank space
 child25 child26 child27                 <== there is leading blank space
 child28 child29 child30                 <== there is leading blank space

Need a script to convert to the following:

Code:
name1 name2
name3 name4
name5 name6 child7 child8 child9
name5 name6 child10 child11 child12
name13 name14
name15 name16 child17 child18 child19
name20 name21 child22 child23 child24
name20 name21 child25 child26 child27
name20 name21 child28 child29 child30

Basically, there is a "leading space" in the "child" line. When ever found, loop through to print with parent "name" to create above output. If no "child" just print the parent "name".

Any help appreciated. Thank you very much.


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 04-26-2017 at 08:15 AM.. Reason: leading blank space in the "child" line not displayed; RudiC: Added CODE tags.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How do I combine the last 2 lines of a file

I tried to put the history line number and the date into the file with one command, and failed. Can't figure out how to get the date variable substituted for the last space captured. history | tail -1 | sed -e 's/.\{7\}/&/g' | head -1 | sed 's/ $/$date/' Result was: 729 $date So, I... (8 Replies)
Discussion started by: jimbob75
8 Replies

2. Shell Programming and Scripting

Combine all lines of a file with all lines of another file.

Dear all, I would like to combine all lines of a file with all lines of another file: The input are file 1 A B C D file 2 A B C D The output is final file A_A A_B A_C (3 Replies)
Discussion started by: valente
3 Replies

3. Shell Programming and Scripting

Combine multiple lines in file based on specific field

Hi, I have an issue to combine multiple lines of a file. I have records as below. Fields are delimited by TAB. Each lines are ending with a new line char (\n) Input -------- ABC 123456 abcde 987 890456 7890 xyz ght gtuv ABC 5tyin 1234 789 ghty kuio ABC ghty jind 1234 678 ght ... (8 Replies)
Discussion started by: ratheesh2011
8 Replies

4. UNIX for Dummies Questions & Answers

Combine lines from file

Hello, Input file looks like this: apples bananas oranges and rice pears cherries mango I want output to look like this: apples bananas oranges and rice pears cherries mango It should combine line 1 with line 2 and line 3 with line 4 like that.... Right now, only way I can... (4 Replies)
Discussion started by: holyearth
4 Replies

5. Shell Programming and Scripting

Combine multiple unique lines from event log text file into one line, use PERL or AWK?

I can't decide if I should use AWK or PERL after pouring over these forums for hours today I decided I'd post something and see if I couldn't get some advice. I've got a text file full of hundreds of events in this format: Record Number : 1 Records in Seq : ... (3 Replies)
Discussion started by: Mayday22
3 Replies

6. UNIX for Dummies Questions & Answers

Combine lines in file

Hi All, I am trying to understand if its possible to carry out the following. I have a text file which contains output from multiple commands, within the file a node will be quiered twice if there was 2 commands for example. Is it possible do combine 2 lines into 1 if the first word is the... (1 Reply)
Discussion started by: mutley2202
1 Replies

7. UNIX for Dummies Questions & Answers

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: _______________________ 5, jaya, male, 4-5-90, single smart 6, prakash, male, 5-4-84, married fair 7, raghavi,... (1 Reply)
Discussion started by: jayaP
1 Replies

8. UNIX for Advanced & Expert Users

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: _______________________ 5, jaya, male, 4-5-90, single smart 6, prakash, male, 5-4-84, married fair 7, raghavi,... (1 Reply)
Discussion started by: jayaP
1 Replies

9. Shell Programming and Scripting

Program to combine two lines in a file on checking the first character of each line

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: _______________________ 5, jaya, male, 4-5-90, single smart 6, prakash, male, 5-4-84, married fair 7, raghavi, female,... (12 Replies)
Discussion started by: jayaP
12 Replies

10. Shell Programming and Scripting

awk to combine matching lines in file

I am trying to combine all matching lines in the tab-delimited using awk. The below runs but no output results. Thank you :). input chrX 110925349 110925532 ALG13 chrX 110925349 110925532 ALG13 chrX 110925349 110925532 ALG13 chrX 47433390 47433999 SYN1... (3 Replies)
Discussion started by: cmccabe
3 Replies
net_instance_notify_register(9F)			   Kernel Functions for Drivers 			  net_instance_notify_register(9F)

NAME
net_instance_notify_register, net_instance_notify_unregister - add/delete a function to be called for changes to an instance SYNOPSIS
#include <sys/hook.h> #include <sys/neti.h> int net_instance_notify_register(net id_t net_id, hook_notify_fn_t *callback, void *arg); int net_instance_notify_unregister(net id_t net_id, hook_notify_fn_t *callback); typedef int (* hook_notify_fn_t)(hook_notify_cmd_t command, void *arg, const char *name1, const char *name2, const char *name3); INTERFACE LEVEL
Solaris DDI specific (Solaris DDI). PARAMETERS
netid value from either callback registered with net_instance_register() or net_zoneidtonetid(). callback function to call when a change occurs. arg pointer to pass into the callback() function when a change occurs. DESCRIPTION
The net_instance_notify_register() function registers a function represented by the pointer callback to be called when there is a new instance added or removed from the given network instance (represented by netid.) The net_instance_notify_unregister() function indicates that there is no longer any desire to receive notification of changes to the instance through function calls to the specified callback. Multiple callback functions may be registered through this interface. The same set of parameters is passed to each callback function. The memory referenced through the pointers passed to the callback should be treated as pointing to read-only memory. Changing this data is strictly prohibited. The function that is called must not block any other events. The arguments passed through to the callback are as follows (the command is either HN_REGISTER or HN_UNREGISTER): name1 is the netid represented as a string. name2 is NULL. name3 is the name of the instance being added/removed RETURN VALUES
If these functions succeed, 0 is returned. Otherwise, the following error is returned: EEXIST the given callback function is already registered. CONTEXT
These functions may be called from user or kernel context. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |Interface Stability |Committed | +-----------------------------+-----------------------------+ SEE ALSO
attributes(5), net_instance_register(9F), net_instance_unregister(9F), net_zoneidtonetid(9F) SunOS 5.11 30 Oct 2008 net_instance_notify_register(9F)
All times are GMT -4. The time now is 01:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy