1

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 
1
  • echo -e "\nappend" >> file Commented Sep 3, 2012 at 14:51

1 Answer 1

2

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.