Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to append first line to the end of second line. I have huge text file where I have to this process for all the entries.

 Value="AF" /> 
<ListItem Text="Afghanistan" 

 Value="AL" />
<ListItem Text="Albania"

 Value="DZ" />
<ListItem Text="Algeria"

 Value="AS" />
<ListItem Text="American Samoa"

 Value="AD" />
<ListItem Text="Andorra"

The output should be on the lines of:

<ListItem Text="Afghanistan" Value="AF" />
<ListItem Text="Albania" Value="AL" />
<ListItem Text="Algeria" Value="DZ" />

Can anyone please help me achieve this? Thanks a lot

share|improve this question

closed as off topic by Alex, womble, John Gardeniers, Scott Pack, Michael Hampton Sep 2 '12 at 23:55

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

Are there 2 blank lines between every 2 blocks? Do you want to keep it in the output? – quanta Aug 10 '12 at 9:59
yes.. 2 blank lines. no. it's better if they aren't present in output. even if they can't be removed, it's fine... :) – Mark Aug 10 '12 at 10:00
up vote 1 down vote accepted
$ sed -e '/^$/d' -e 'N;s/\(.*\)\n\(.*\)/\2\1/' input.txt
  • /^$/d - delete all the blank lines
  • N - put the next line into the pattern space
  • s - substitute
  • \(.*\)\n\(.*\) - matching the first line, followed by newline and the second line
  • \2\1 - append the first line to the end of second line by using back reference
share|improve this answer
wow... really thanks a million :) you're great... :) – Mark Aug 10 '12 at 10:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.