LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 11-27-2007, 06:15 AM   #16
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63

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
 
Old 11-28-2007, 01:20 PM   #17
LMSSML
Member
 
Registered: Nov 2007
Distribution: Ubuntu Server and Desktop
Posts: 41

Original Poster
Rep: Reputation: 15
Smile 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
 
Old 12-02-2007, 05:53 AM   #18
LMSSML
Member
 
Registered: Nov 2007
Distribution: Ubuntu Server and Desktop
Posts: 41

Original Poster
Rep: Reputation: 15
Cool 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
 
Old 12-02-2007, 08:20 AM   #19
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
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.
 
Old 12-04-2007, 06:50 AM   #20
LMSSML
Member
 
Registered: Nov 2007
Distribution: Ubuntu Server and Desktop
Posts: 41

Original Poster
Rep: Reputation: 15
awk

Hi

Thanks Mathew (again)

But could awk be more quicker than my script ?

Thanks
 
Old 12-04-2007, 07:29 AM   #21
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
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;
        }
}
 
Old 12-04-2007, 06:26 PM   #22
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,311

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


Reply

Tags
awk, chmod, integer, io, linux, performance, perl, read, redirection, scripts, shell, shell script, speed, while


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
help with linux commands jld9 Linux - Newbie 7 10-23-2007 08:45 PM
Linux Commands a_newlinuxguy Linux - General 15 03-06-2007 02:53 PM
Suse Linux Commands For These Aix Commands? Vaskar Guha Linux - Software 2 12-19-2005 01:45 AM
Linux commands... hkxx9 Linux - Newbie 2 09-15-2004 09:49 AM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration