# Else statement in looking for a character

**URL:** <https://community.unix.com/t/else-statement-in-looking-for-a-character/374058>\
**Category:** Shell Programming and Scripting\
**Created:** [November 1, 2018, 10:10am UTC](https://community.unix.com/t/else-statement-in-looking-for-a-character/374058 "2018-11-01T10:10:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![invinzin21](https://community.unix.com/letter_avatar/invinzin21/32/6_449c533f586939b6e5f246632a46421f.png) [@invinzin21](https://community.unix.com/u/invinzin21)\
**Post date:** [November 1, 2018, 10:10am UTC](https://community.unix.com/t/else-statement-in-looking-for-a-character/374058/1 "2018-11-01T10:10:00Z")

</div>

I have list of hostnames with

```nohighlight
# cat list
servdc01
servdc02
compdc01
compdc02
servit01
servit02
prindc01
datacenter01
dcenit01
dcendc01
[root]

If the hostname has dc in 5,6. Copy a file dedicated for them,
if the hostname has IT in 5,6. Copy a file dedicated for them.

```

```nohighlight
dc=`cat list|grep dc` # I cant do this because it will get this data dcendc01
it= `cat list|grep it`
if [$dc -ne 0]
then
cp /files/intended_for_dc_hosts $dc
fi

if [$it -ne 0]
then
cp /files/intended_for_it_hosts $it
fi
. . .

```

---

<div class="post-metadata">

**Author:** ![vgersh99](https://community.unix.com/user_avatar/community.unix.com/vgersh99/32/14851_2.png) [@vgersh99](https://community.unix.com/u/vgersh99)\
**Post date:** [November 1, 2018, 10:26am UTC](https://community.unix.com/t/else-statement-in-looking-for-a-character/374058/2 "2018-11-01T10:26:30Z")

</div>

if you insist on using grep....

```nohighlight
grep -E '^....dc' myFile
grep -E '^....it' myfile

```
