LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-18-2007, 12:19 PM   #1
keceli
LQ Newbie
 
Registered: Jul 2007
Posts: 2

Rep: Reputation: 0
bash vs perl vs python


I am a beginner, and want to learn which language is better for file editing purposes.

Particularly what i am looking for is to read some numbers (or strings) from a file "A" (taking the largest n numbers or the numbers in certain lines or a certain string) and then insert them into a specific part of another file "B". (I need to replace a text in file "B")

As far as i know perl is good for string manipulations, but if it could be done by bash scripts, maybe that's easier.
 
Old 07-18-2007, 01:46 PM   #2
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
I would suggest Perl for that.
Perl = Practical Extraction and Reporting Language
That sort of stuff can get messy with Bash.
 
Old 07-18-2007, 02:15 PM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
I would also look at Python...

Disclosure: I am not a programmer. I do have a working knowledge of C, and have most recently started learning Python. There is something about the simplicity of Python that is quite appealling--and the tutorial on the official site is among the best I have ever seen.

Any of the 3 will work--bash scripting is maybe the hardest to learn.
 
Old 07-19-2007, 03:24 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,283

Rep: Reputation: 172Reputation: 172
shell scripting is good for simple, general admin at whole file and directory level
but when you start cutting up files and playing with them, it rapidly
runs out of power.

perl and python are both great languages,
perl is more ubiquitous on a range of unix machines, python prettier
and more elegant.

Last edited by bigearsbilly; 07-19-2007 at 03:27 AM.
 
Old 07-19-2007, 03:46 AM   #5
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 240Reputation: 240Reputation: 240
Quote:
Originally Posted by keceli
I am a beginner, and want to learn which language is better for file editing purposes.

Particularly what i am looking for is to read some numbers (or strings) from a file "A" (taking the largest n numbers or the numbers in certain lines or a certain string) and then insert them into a specific part of another file "B". (I need to replace a text in file "B")

As far as i know perl is good for string manipulations, but if it could be done by bash scripts, maybe that's easier.
if you want to stick to shell, awk and sed are the next most suitable tools you can use.
 
Old 07-19-2007, 04:07 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,283

Rep: Reputation: 172Reputation: 172
hmm,
at risk of a flame war, sed and awk are pretty much subsets of perl
now.
sed is still useful sometimes but only for one-liners.
 
Old 07-19-2007, 04:23 AM   #7
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 240Reputation: 240Reputation: 240
Quote:
Originally Posted by bigearsbilly
hmm,
at risk of a flame war, sed and awk are pretty much subsets of perl
now.
i agree, however let's stick to what OP wants, file editing, getting some text in file A and replace with text in file B. This task can be done with just shell tools, all depending on the OP's choice of tools of course. If he wants to use Perl then by all means.
Quote:
sed is still useful sometimes but only for one-liners.
not true. If you read the recent "debate" on sed on a previous thread, sed is turing complete, so it can do more than just one-liners, albeit more "tedious" to code to perform certain tasks.
 
Old 07-19-2007, 11:38 PM   #8
keceli
LQ Newbie
 
Registered: Jul 2007
Posts: 2

Original Poster
Rep: Reputation: 0
thanks all, I used perl, the following commands were very useful,
@array=fileAhandle #writes all file line by line to array
print fileBhandle @newarrayB #writes the new array to file
 
Old 07-20-2007, 12:21 AM   #9
iwasapenguin
Member
 
Registered: Jul 2007
Posts: 110

Rep: Reputation: 15
I know less than I should about half-a-dozen or so languages so I'm not the perfect person to give advice but my rule of thumb is to program in the language made for your job. In this case perl, python is good as a learning tool and can be used to extend the functions of a lot of programms, shell scripts are for linking to gether the utilities on the shell.
 
Old 07-20-2007, 09:35 AM   #10
rizhun
Member
 
Registered: Jun 2005
Location: England
Distribution: Ubuntu, SLES, AIX
Posts: 268

Rep: Reputation: 47
Concidering you are a beginner and the task you are trying to accomplish, Perl is the obvious winner.

Get yourself the 'Learning Perl' O'Reilly book - it's very good.

Once you have mastered Perl you won't have any trouble picking up most other languages.
 
Old 07-23-2007, 08:21 PM   #11
iwasapenguin
Member
 
Registered: Jul 2007
Posts: 110

Rep: Reputation: 15
For that matter typing man -k perl into your terminal will bring up a good list of manuals on perl that cover pretty much everything.
 
Old 07-23-2007, 10:57 PM   #12
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,239

Rep: Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024
Here is the motherlode for Perl; includes lang def with examples, plus tutorials and more.
http://perldoc.perl.org/
 
  


Reply


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
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 04:11 AM
Python or Perl drdroid Programming 29 12-22-2006 09:54 AM
Python or Perl? Boby Programming 2 06-12-2005 10:54 AM
bash, perl, or python? s_siouris Linux - Software 11 05-13-2005 03:15 PM
Perl or Python ! linuxlover1 Programming 13 04-19-2004 07:33 AM


All times are GMT -5. The time now is 09:13 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