# How to simplify this code?

**URL:** <https://community.unix.com/t/how-to-simplify-this-code/336145>\
**Category:** Shell Programming and Scripting\
**Created:** [October 31, 2013, 11:27pm UTC](https://community.unix.com/t/how-to-simplify-this-code/336145 "2013-10-31T23:27:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zulabc](https://community.unix.com/letter_avatar/zulabc/32/5_5575768a8748004e209b776fc1b2916d.png) [@zulabc](https://community.unix.com/u/zulabc)\
**Post date:** [October 31, 2013, 11:27pm UTC](https://community.unix.com/t/how-to-simplify-this-code/336145/1 "2013-10-31T23:27:57Z")

</div>

hi guys need your help...how to simplify this script...

```nohighlight
 for i in `cat dmp.txt`
  do

    model=$i
    more $model | grep : | cut -d ":" -f 2- | grep : | grep -v "=" > temp1
    more $model | grep / | cut -d ":" -f 2- > temp2
    more $model | grep = | cut -d ":" -f 2- > temp3
    more $model | grep ";" | cut -d ":" -f 2- | cut -d ";" -f 1- > temp4
    model_1=`echo $model | cut -d "." -f 1`

```

---

<div class="post-metadata">

**Author:** ![RavinderSingh13](https://community.unix.com/letter_avatar/ravindersingh13/32/5_5575768a8748004e209b776fc1b2916d.png) [@RavinderSingh13](https://community.unix.com/u/RavinderSingh13)\
**Post date:** [October 31, 2013, 11:46pm UTC](https://community.unix.com/t/how-to-simplify-this-code/336145/2 "2013-10-31T23:46:19Z")

</div>

Hi,

Could you please provide the Input and expected Output for same.

Thanks,  
R. Singh

---

<div class="post-metadata">

**Author:** ![Don\_Cragun](https://community.unix.com/user_avatar/community.unix.com/don_cragun/32/2682_2.png) [@Don\_Cragun](https://community.unix.com/u/Don_Cragun)\
**Post date:** [November 1, 2013, 2:23am UTC](https://community.unix.com/t/how-to-simplify-this-code/336145/3 "2013-11-01T02:23:45Z")

</div>

> [@zulabc](#):
>
> hi guys need your help...how to simplify this script...
> 
> ```plaintext
> for i in `cat dmp.txt`
> do
> 
> model=$i
> more $model | grep : | cut -d ":" -f 2- | grep : | grep -v "=" > temp1
> more $model | grep / | cut -d ":" -f 2- > temp2
> more $model | grep = | cut -d ":" -f 2- > temp3
> more $model | grep ";" | cut -d ":" -f 2- | cut -d ";" -f 1- > temp4
> model_1=`echo $model | cut -d "." -f 1`
> 
> ```

In addition to what RavinderSingh13 has already said...

Given that this script is incomplete, invokes more four times when it doesn't need to call it at all, sets a variable that isn't needed, seems to waste time creating 4 temporary files that are not used, and seems to waste time setting a variable that isn't used, the following simplified version of your code should produce the same syntax error as your current script:

```plaintext
for i in `cat dmp.txt`
  do

```

If you would show us your complete script, tell us what shell you're using, what operating system you're using, what is in the files listed in the file named dmp.txt, whether any of the filenames in dmp.txt could contain any spaces or tabs, and what output you want your script to produce; we might be able to help.
