can someone help me understand this command and how it works please.
Bob@localhost [/home/Bob]
$ cat phone.list
Smith, Terry 7-7989
Adams, Fran 2-3876
StClair, Pat 4-6122
Brown, Robin 1-3745
Stair, Chris 5-5972
Benson, Sam 4-5587
Bob@localhost [/home/Bob]
$ cp phone.list phone.list2
Bob@localhost [/home/Bob]
$ sed '/Brown/s//Browne/' phone.list2 >> phone.list2
Bob@localhost [/home/Bob]
$ cat phone.list2
Smith, Terry 7-7989
Adams, Fran 2-3876
StClair, Pat 4-6122
Brown, Robin 1-3745
Stair, Chris 5-5972
Benson, Sam 4-5587
Smith, Terry 7-7989
Adams, Fran 2-3876
StClair, Pat 4-6122
Browne, Robin 1-3745
Stair, Chris 5-5972
Benson, Sam 4-5587
Bob@localhost [/home/Bob]
$ cp phone.list phone.list3
Bob@localhost [/home/Bob]
$ sed '/Brown/s//Browne/' phone.list3 > phone.list3
Bob@localhost [/home/Bob]
$ cat phone.list3
Bob@localhost [/home/Bob]
Can someone please help me understand how this works.
When a double redirection is given in the command it displays <content> along with the updated content appended to it. It is mentioned in the book(Unix Applications Programming Mastering the Shell by Ray Swartz) that the shell always scans a command line for shell meta characters before creating a process to execute the command. As a result (when single redirection is used), the shell sets up the redirection, which erases the contents of phone.list, before sed can get a chance to look at it.
With this mentioned in the book, when we give double redirection ">>" wouldn't the shell first scan the file phone.list2 and then perform the sed operation. If it does so then shouldn't we be getting a different output.
Please explain. Thanks in advance.
|