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'm trying to write a perl script which deletes usernames in a file. Since perl does not have the tools (or does it?) to delete lines directly in a file, I tried to open the file with an linux editor:
exec('ex /home/users/johanl/data/praatjes');
so far so good (exept for the small thing, I would like to use something like
exec('ex $file');
but that doesn't work.)
but now, whatever I do, every time I execute the script it stops at de ex prompt.
How do I give commands like "go to line $count" ($countG?) and "delete this line" (dd?)
first off, exec REPLACES your process, so control will not be returned to your script (unless there's a problem). second, just open your file in perl, name it xfile.newfile and write to that every line but the one you want to delete .... or look up the -i option (is that the edit-in-place one? I can never remember ...)
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152
Rep:
Perl is perfect for processing text files. Point your browser to the
Perl web page, and read up on it. You don't need to use an editor. http://learn.perl.org
I tried the -i option or -i.bak to make a backup also, but it doesn't work (or I don't use it in the right way )
I will try pipe programming this afternoon, maybe that offers me a way out.
I thought about writing things to another file, but I want to settle this for all Suppose I have a huge file, and I want to do the same thing: search for a line and delete it... then writing the file would cost the same huge amount of disk space.
and moses:
that's a beautiful site you gave me, but as far as I can see it only offers books for sale?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.