XML 파일에 줄을 추가하는 방법

XML 파일에 줄을 추가하는 방법

XML 파일에 한 줄을 추가하고 싶습니다. 내 XML 파일에는 다음이 포함되어 있습니다.

<?xml version="1.0" encoding="UTF-8"?> 
<configuration>     
  <ftp_destination_ip>0.0.0.0</ftp_destination_ip>
  <ftp_destination_user>root</ftp_destination_user>
  <ftp_destination_pass>undefined</ftp_destination_pass>        
  <other_unix_backup_path>/root/BACKUP</other_unix_backup_path>
  <other_backup_folder>BACKUP</other_backup_folder>
  <source_confirmation_needed>false</source_confirmation_needed>
  <keep_ems_running_after_restore>false</keep_ems_running_after_restore>
  <remote_connection_timeout>120000</remote_connection_timeout >
    <history>
        <manage_backup_history>true</manage_backup_history>
        <backup_history_num_of_days>7</backup_history_num_of_days>
    </history>
</configuration>

XML에 세 번째와 네 번째 줄 두 줄을 추가하고 싶습니다.

  <remote_connection_protocol>sftp</remote_connection_protocol>
  <ftp_destination_ip>0.0.0.0</ftp_destination_ip>

출력은 다음과 같아야 합니다.

<?xml version="1.0" encoding="UTF-8"?> 
<configuration>     
  <!--remote connection protocol>false|ftp|sftp</remote connection protocol-->
  <remote_connection_protocol>sftp</remote_connection_protocol>
  <ftp_destination_ip>0.0.0.0</ftp_destination_ip>
  <ftp_destination_user>root</ftp_destination_user>
  <ftp_destination_pass>undefined</ftp_destination_pass>        
  <other_unix_backup_path>/root/BACKUP</other_unix_backup_path>
  <other_backup_folder>BACKUP</other_backup_folder>
  <source_confirmation_needed>false</source_confirmation_needed>
  <keep_ems_running_after_restore>false</keep_ems_running_after_restore>
  <remote_connection_timeout>120000</remote_connection_timeout >
    <history>
        <manage_backup_history>true</manage_backup_history>
        <backup_history_num_of_days>7</backup_history_num_of_days>
    </history>
</configuration>

감사해요

답변1

이 시도,

sed '4i\  <remote_connection_protocol>sftp</remote_connection_protocol>\n  <ftp_destination_ip>0.0.0.0</ftp_destination_ip>' file.xml
  • 4i파일의 4번째 줄에 내용을 추가합니다.
  • \n개행 문자.

작동하는 경우 -i인라인 편집 옵션을 추가하세요.

관련 정보