# Script Help

**URL:** <https://community.unix.com/t/script-help/239286>\
**Category:** Shell Programming and Scripting\
**Created:** [May 4, 2009, 10:49pm UTC](https://community.unix.com/t/script-help/239286 "2009-05-04T22:49:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zxc](https://community.unix.com/letter_avatar/zxc/32/6_449c533f586939b6e5f246632a46421f.png) [@zxc](https://community.unix.com/u/zxc)\
**Post date:** [May 4, 2009, 10:49pm UTC](https://community.unix.com/t/script-help/239286/1 "2009-05-04T22:49:15Z")

</div>

I have a file called zxc where there are names and ages, like:

Pedro 23  
Mike 18  
Pedro 27

i want to create a shell script that i can run like this

name Pedro

output: (must be sorted)

Pedro 23  
Pedro 27

I would like to use use grep, sort, and positional parameters

Thanks

---

<div class="post-metadata">

**Author:** ![devtakh](https://community.unix.com/letter_avatar/devtakh/32/6_449c533f586939b6e5f246632a46421f.png) [@devtakh](https://community.unix.com/u/devtakh)\
**Post date:** [May 4, 2009, 11:03pm UTC](https://community.unix.com/t/script-help/239286/2 "2009-05-04T23:03:58Z")

</div>

use

```nohighlight
sed -n "s/$1/p" filename

```

cheers,  
Devaraj Takhellambam

---

<div class="post-metadata">

**Author:** ![zxc](https://community.unix.com/letter_avatar/zxc/32/6_449c533f586939b6e5f246632a46421f.png) [@zxc](https://community.unix.com/u/zxc)\
**Post date:** [May 4, 2009, 11:06pm UTC](https://community.unix.com/t/script-help/239286/3 "2009-05-04T23:06:30Z")

</div>

> [@devtakh](#):
>
> use
> 
> ```plaintext
> sed -n "s/$1/p" filename
> 
> ```
> 
> cheers,  
> Devaraj Takhellambam

like i said i want to use grep and sort.. thanks

---

<div class="post-metadata">

**Author:** ![devtakh](https://community.unix.com/letter_avatar/devtakh/32/6_449c533f586939b6e5f246632a46421f.png) [@devtakh](https://community.unix.com/u/devtakh)\
**Post date:** [May 5, 2009, 12:26am UTC](https://community.unix.com/t/script-help/239286/4 "2009-05-05T00:26:36Z")

</div>

> [@zxc](#):
>
> like i said i want to use grep and sort.. thanks

```plaintext
grep "$1" filename 2> /dev/null | sort +2n

```

cheers,  
Devaraj Takhellambam

---

<div class="post-metadata">

**Author:** ![summer\_cherry](https://community.unix.com/letter_avatar/summer_cherry/32/6_449c533f586939b6e5f246632a46421f.png) [@summer\_cherry](https://community.unix.com/u/summer_cherry)\
**Post date:** [May 5, 2009, 3:09am UTC](https://community.unix.com/t/script-help/239286/5 "2009-05-05T03:09:57Z")

</div>

```nohighlight
name=$(echo ${1-Pedro})
cat a.txt | grep ${name}

```
