How to simplify this code?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to simplify this code?
# 1  
Old 11-01-2013
How to simplify this code?

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

Code:
 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`


Last edited by Don Cragun; 11-01-2013 at 02:46 AM.. Reason: Add CODE tags.
# 2  
Old 11-01-2013
Hi,

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


Thanks,
R. Singh
# 3  
Old 11-01-2013
Quote:
Originally Posted by zulabc
hi guys need your help...how to simplify this script...

Code:
 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:
Code:
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Programming

Simplify setter and getter of java class

I am trying to verify my understanding on setter and getter on java class with this example: //MaximumFinder2.java import java.util.Scanner; public class MaximumFinder2 { public static void main (String args) { Scanner input = new Scanner(System.in); ... (6 Replies)
Discussion started by: yifangt
6 Replies

2. Shell Programming and Scripting

Need to simplify code list files in directory

I have the following code that print certain files in my directory and groups things together. I would be good to tidy and simplify this code up and would greatly appreciate suggestions. if ($opt_raytrac == 1) then echo "" echo -n "\033*\)/ & /g' | sort -k 4n | sed 's/ //g' \ # |... (0 Replies)
Discussion started by: kristinu
0 Replies

3. Shell Programming and Scripting

simplify regular expressions

Hi can anyone help me with how to simplify this regular expression ---------- Post updated at 09:16 PM ---------- Previous update was at 09:11 PM ---------- IS THIS RIGHT ? (3 Replies)
Discussion started by: drew211
3 Replies

4. Shell Programming and Scripting

simplify/combine if statements would be nice

below is something i inherited: if && && ; then HOST_SELECT="-m quadcore" fi if && && ; then HOST_SELECT="-m quadcore" fi if && && ; then HOST_SELECT="-m octocore1" fibelow is what i changed it to: if && && ; then HOST_SELECT="-m quadcore"... (2 Replies)
Discussion started by: crimso
2 Replies

5. Shell Programming and Scripting

Can I simplify this script?

Hi all, I have a script which runs every morning which clears down a series of directories. The structures of which are; /opt/feeds/failed/feed1 /opt/feeds/succeed/feed1 /opt/feeds/failed/feed2 /opt/feeds/succeed/feed2 /opt/feeds/failed/feed3 /opt/feeds/succeed/feed3 etc etc Files... (6 Replies)
Discussion started by: JayC89
6 Replies

6. Shell Programming and Scripting

Help to simplify with awk

Hi, Need your help guys. I'm trying to tweak my current shell-script to make it run faster. I think a part of the code that takes too long is the splitting of the 1st field of my CSV raw-file to date-time. Below is the 1st column of my CSV file: $ awk -F"," {'print $1'} temp-*|head... (5 Replies)
Discussion started by: daytripper1021
5 Replies

7. Shell Programming and Scripting

How can I simplify the script

Hi all, How can I simplify following script, Logic is to find two strings (strings are case sensitive) from a file. if ; then if ; then Group=`echo $1_hostname` fi fi Please help me on this. Regards Sudhish s. kumar (8 Replies)
Discussion started by: sudhish
8 Replies

8. Shell Programming and Scripting

a script to simplify the use of grep

I'm trying to write a script that simplify the use of grep utility. these are the option that I'd like to use with the script " -c -i -l -n -v". When I execute the script none of these option works. I really appreciate any idea or tips regarding this problem. here the code echo " Enter 1-7:"... (2 Replies)
Discussion started by: kemobyte
2 Replies
Login or Register to Ask a Question