ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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.
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.
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.