Monday, May 30, 2011

sed quit operator and seq operator

The seq operator in shell is to generate sequential numbers.As you can see.


 acer@ubuntu:~$ seq 10
1
2
3
4
5
6
7
8
9
10
And the quit operator in sed is mainly used to quit when aa particular match or substitution occurs.


acer@ubuntu:~$ seq 10 | sed '4 q'
1
2
3
4
acer@ubuntu:~$

As you may see from the above example the ouput is stopped once the match occurs.

substitute within a range


In this case we will see how we can use sed command within a particular range

for example we try to substitute the words inbetween wonderful and marvellous.
leaving behind the first and last word.

Content of the file to be modified:

acer@ubuntu:~$ cat ggg
hello life
wonderful
great
marvellous
awesome

OUTPUT with execution:

acer@ubuntu:~$ sed '/wonderful/, /marvellous/ s/.*/modified/' ggg
hello life
modified
modified
modified
awesome
acer@ubuntu:~$