Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

please advice how it can be - ( this action was on linux machine )

why the string - "append" that I add with echo is after the line "spb_IP=172.17.100.122"

and not under the line - "spb_IP=172.17.100.122" ????

more file

 spa_IP=172.17.100.121
 spb_IP=172.17.100.122

echo "append" >> file

more file

 spa_IP=172.17.100.121
 spb_IP=172.17.100.122append this
share|improve this question
    
echo -e "\nappend" >> file –  InternetSeriousBusiness Sep 3 '12 at 14:51

1 Answer 1

up vote 2 down vote accepted

This will be because the file does not end in a \n.

hexdump -C file
00000000  73 70 61 5f 49 50 3d 31  37 32 2e 31 37 2e 31 30  |spa_IP=172.17.10|
00000010  30 2e 31 32 31 0a 73 70  61 5f 49 50 3d 31 37 32  |0.121.spa_IP=172|
00000020  2e 31 37 2e 31 30 30 2e  31 32 32                 |.17.100.122|

Note the file ends in 0x32 which is ASCII for 2

When you append to it it becomes

hexdump -C file
00000000  73 70 61 5f 49 50 3d 31  37 32 2e 31 37 2e 31 30  |spa_IP=172.17.10|
00000010  30 2e 31 32 31 0a 73 70  61 5f 49 50 3d 31 37 32  |0.121.spa_IP=172|
00000020  2e 31 37 2e 31 30 30 2e  31 32 32 61 70 70 65 6e  |.17.100.122appen|
00000030  64 0a

Note that as you have observed the 122 runs straight into the append 122append

To fix your 'problem' you need to

echo -e "\nappend" 

to add the missing \n.

hexdump -C file
00000000  73 70 61 5f 49 50 3d 31  37 32 2e 31 37 2e 31 30  |spa_IP=172.17.10|
00000010  30 2e 31 32 31 0a 73 70  61 5f 49 50 3d 31 37 32  |0.121.spa_IP=172|
00000020  2e 31 37 2e 31 30 30 2e  31 32 32 0a 61 70 70 65  |.17.100.122.appe|
00000030  6e 64 0a                                          |nd.|

Now there is a . between the 122 and the append which represents the 0x0a (ASCII line Feed) character.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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