# How to delete expression in the brackets?

**URL:** <https://community.unix.com/t/how-to-delete-expression-in-the-brackets/285324>\
**Category:** Shell Programming and Scripting\
**Created:** [March 28, 2011, 12:10am UTC](https://community.unix.com/t/how-to-delete-expression-in-the-brackets/285324 "2011-03-28T00:10:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tkmmelvin](https://community.unix.com/letter_avatar/tkmmelvin/32/5_5575768a8748004e209b776fc1b2916d.png) [@tkmmelvin](https://community.unix.com/u/tkmmelvin)\
**Post date:** [March 28, 2011, 12:10am UTC](https://community.unix.com/t/how-to-delete-expression-in-the-brackets/285324/1 "2011-03-28T00:10:11Z")

</div>

how to delete second part in the expression sshd[19557] using gsub function so that output look likes sshd.

Thanks.

---

<div class="post-metadata">

**Author:** ![cgkmal](https://community.unix.com/letter_avatar/cgkmal/32/5_5575768a8748004e209b776fc1b2916d.png) [@cgkmal](https://community.unix.com/u/cgkmal)\
**Post date:** [March 28, 2011, 12:19am UTC](https://community.unix.com/t/how-to-delete-expression-in-the-brackets/285324/2 "2011-03-28T00:19:26Z")

</div>

> [@tkmmelvin](#):
>
> how to delete second part in the expression sshd[19557] using gsub function so that output look likes sshd.
> 
> Thanks.

Hi tkmmelvin,

Try with:

`gsub(/\[.*\]/,"")`

So similar what is in:

[156815-cut-column-edit-data.html](http://www.unix.com/shell-programming-scripting/156815-cut-column-edit-data.html)

Regards

---

<div class="post-metadata">

**Author:** ![kurumi](https://community.unix.com/letter_avatar/kurumi/32/5_5575768a8748004e209b776fc1b2916d.png) [@kurumi](https://community.unix.com/u/kurumi)\
**Post date:** [March 28, 2011, 12:22am UTC](https://community.unix.com/t/how-to-delete-expression-in-the-brackets/285324/3 "2011-03-28T00:22:00Z")

</div>

```nohighlight

$ echo "sshd[19557]" | ruby -e 'puts gets.split("[",2)[0]'
sshd

```

---

<div class="post-metadata">

**Author:** ![Chubler\_XL](https://community.unix.com/user_avatar/community.unix.com/chubler_xl/32/2077_2.png) [@Chubler\_XL](https://community.unix.com/u/Chubler_XL)\
**Post date:** [March 28, 2011, 2:10am UTC](https://community.unix.com/t/how-to-delete-expression-in-the-brackets/285324/4 "2011-03-28T02:10:12Z")

</div>

That's not using the gsub function!

---

<div class="post-metadata">

**Author:** ![tene](https://community.unix.com/letter_avatar/tene/32/5_5575768a8748004e209b776fc1b2916d.png) [@tene](https://community.unix.com/u/tene)\
**Post date:** [March 28, 2011, 2:23am UTC](https://community.unix.com/t/how-to-delete-expression-in-the-brackets/285324/5 "2011-03-28T02:23:06Z")

</div>

```nohighlight
echo "sshd[19557]" | awk -F"[" '{print $1}'
sshd

```
