-2

The content in fileA is:

Here’s the ip list.

ip: 2.2.3.4
ip: 2.2.3.5
ip: 2.2.3.6
ip: 2.2.3.7

The content is fileB is

ip: 1.2.3.4
ip: 1.2.3.5
ip: 1.2.3.6
ip: 1.2.3.7

How to use sed command or other commands in a bash script to produce a list below?

Here’s the ip list.

ip: 1.2.3.4
ip: 1.2.3.5
ip: 1.2.3.6
ip: 1.2.3.7

ip: 2.2.3.4
ip: 2.2.3.5
ip: 2.2.3.6
ip: 2.2.3.7

'cat fileA fileB' would only append fileB to fileA. If I insert a keyword into fileA first and then replace the keyword with fileB's text, all lines from fileB's text would combine into one line when being assigned to a variable.

t=$(cat fileB) 
sed '/[keyword]/c\$t' fileA

closed as off-topic by mdpc, yoonix, Andrew Schulman, Sven Dec 6 '14 at 13:57

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions must be relevant to professional system administration. Server Fault is dedicated to professional system and network administrators. End user and enthusiast questions are off-topic (contact your system administrator or hire a professional to help you out). Please see the Help Center for more information." – mdpc, Andrew Schulman, Sven
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Re your edit: No one "abused his power". Your question is hard to understand, so two users (which might be entirely different from those who close-voted it) downvoted it. Write better questions that are clearly topical and this won't happen. See the help center and How to ask better questions on Serverfault – Sven Dec 7 '14 at 9:09
1

Unless I misunderstand, how about you append

cat filea >> fileb

You can do a sort afterwards, if that's what you're after.

  • There are lines that need to keep at the top in fileA. It could be more than one line that need to be at the top. – Purres Dec 6 '14 at 3:13
  • So... cat fileb >> filea – Hyppy Dec 6 '14 at 3:31

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