LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using linux commands (https://www.linuxquestions.org/questions/linux-newbie-8/using-linux-commands-602094/)

matthewg42 11-27-2007 05:15 AM

In part 2 what do you mean "compares"? That suggests that some operation should be performed if some condition is true, but you do not say what.

In general, you can use a while read loop to take input from the keyboard:
Code:

echo -n "Enter a file name> "
while read filename; do
    if [ "$filename" = "" ]; then
        echo "Nothing entered.  I will not ask again"
        break
    fi
    echo "I got this: $filename"
    echo -n "Enter another file name> "
done


LMSSML 11-28-2007 12:20 PM

sorry for my late explanation (LOL)
 
Hi mathew,


What I want to says with "compares" in a short example it's something like this.

Input from user

tabela2.txt

v:=read (file)

the file will be stored in v so now we could make the "compare"

z is a list where inside has something like this:

tabela1.txt 158 (characaters)
tabela2.txt 38 (characters)
tabela3.txt 45 (characters)

if v exist in z then

(it goes to the 8th cycle) and do something like this.
:8

while read line; do
if [ ${#line} -lt 38 ]; then
echo "${line}0"
else
echo "${line}"
fi
done

but if the file it's tabela3.txt then he goes to

:7
while read line; do
if [ ${#line} -lt 45]; then
echo "${line}0"
else
echo "${line}"
fi
done

Thanks

LMSSML 12-02-2007 04:53 AM

Speed up to analyse
 
Hi there !!

Is any way to accelarate scripts on Linux

I've got files with 1 million (near of 2 million) of lines and to analyse 12 files it takes 2 days if I have 70 files it will be longer with the time.

Is there anyway to accelarate this situation ?

Thanks

best Rgeards

matthewg42 12-02-2007 07:20 AM

Shell scripts are really a quick and quite slow glue for combining the functionality of other programs. As I told you in post #5 of this thread, they are not good for line-by-line editing of large sets of data. You should consider writing your program in a language more suited to the task, such as Perl or Python.

LMSSML 12-04-2007 05:50 AM

awk
 
Hi

Thanks Mathew (again)

But could awk be more quicker than my script ?

Thanks

matthewg42 12-04-2007 06:29 AM

For sure awk will be a lot faster than a shell script in this case. Perl will probably be even faster, although it's more to learn than awk, so maybe awk would be easier to get started with.

For example, I created a large test file (15 meg / 100000 lines) and ran the shell script on it. The time used by the process was over 31 seconds. When I did the same thing with an awk program it took just 1.7 seconds. A similar program written in Perl took less than half a second.

The text processing part of the program in awk looks like this:
Code:

{
        if ( length($0) < 38 ) {
                print $0 "0";
        }
        else {
                print $0;
        }
}


chrism01 12-04-2007 05:26 PM

If you decide to go with Perl, start here: http://perldoc.perl.org/


All times are GMT -5. The time now is 02:56 AM.