A A A
logo2




Sed stream editor that is. Perform some shares with the data input.



Script executing


The script can be invoked in two ways:

If you write directly on the command line and specifying the contents of the script file name with the data:

owi@laptop:~$ sed 'tresc skryptu' dane

dane – file with data



Writing a script in a separate file:

owi@laptop:~$ sed -f skrypt dane

skrypt- file with script
dane – file with data



Building a script



address command [arguments]

Part of the address to be responsible for which line will be taken into account. Address can be given by numbers (eg 3) or by quoting the words written in a particular line (eg / BBB / BBB where the regular expression, which is the model to match). The command determines what to change. In contrast, the argument may be, for example text.


i- add the text given as an argument against the selected line

Example 1

content of the script:


owi@laptop:~$ sed '3i ala ma kota' dane

Before the third line of text will be added „ala ma kota”.



a- add the text given as an argument after the selected line

Example 2

content of the script:


owi@laptop:~$ sed '6a ala ma kota' dane

After the sixth line of text will be added "ala ma kota".



p- displays the specified line

Example 3



owi@laptop:~$ sed -n '4p' dane

You will see only 4 lines.



Example 4



owi@laptop:~$ sed -n '4,6p' dane

You will see lines 4 to 6.



Example 5



owi@laptop:~$ sed -n '/ala/,/kasia/p' dane

You will see all the lines between the beginning and at the ala at checkout.



Example 6



owi@laptop:~$ sed -n '4,6!p' dane

Exclamation point before the letter P is the negation. Do not be so displayed lines 4 to 6

WARNING!
To run the script from the command as the second church (ie, sed-f script data) should be before you add the-f -n.




q– displays the specified lines to the script and ends

Example 7



owi@laptop:~$ sed '3q' dane

You will see only the first 3 lines.



d – does not display the lines indicated

Example 8



owi@laptop:~$ sed '3,$d' dane

Do not display the line from 3 to the last, because the $ symbol to the last line.



s– turns to the other lines shown

Example 9



owi@laptop:~$ sed 's/ala/kasia/g' dane

The word from the ala will be converted into lines with the word kasia. The letter G indicates that it will be the whole file and not only in the first napotkanej line.





Autor: Aleksandra Przybyło
aleksandraprzybylo@gmail.com