LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 01-07-2003, 05:16 PM   #1
JohanLingen
LQ Newbie
 
Registered: Jan 2003
Posts: 9

Rep: Reputation: 0
vim commands in perl


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?)

your help would be appreciated
 
Old 01-07-2003, 08:11 PM   #2
lackluster
Member
 
Registered: Apr 2002
Location: D.C - USA
Distribution: slackware-current
Posts: 488

Rep: Reputation: 30
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 ...)
 
Old 01-07-2003, 08:17 PM   #3
lackluster
Member
 
Registered: Apr 2002
Location: D.C - USA
Distribution: slackware-current
Posts: 488

Rep: Reputation: 30
also, you can pipe to a program using

Code:
open (PIPEY, "| emacs"); # I don't know vi(?:m)?
print PIPEY '#!/usr/bin/perl'."\n\n";
print PIPEY 'print "Just Another Perl Hacker\n";'."\n";
print PIPEY <ctrl-x><ctrl-f>; #don't know the values .. .sorry
print PIPEY "genfile.pl\n";
close PIPEY;
system("chmod +x genfile.pl");
exec("genfile.pl");
die ("Something wrong executing genfile.pl!\n$!\n");
THis code is untested, and most probably littered with a syntax error or so, but hopefully you get the idea.
 
Old 01-07-2003, 09:10 PM   #4
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 50
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
 
Old 01-08-2003, 04:29 AM   #5
JohanLingen
LQ Newbie
 
Registered: Jan 2003
Posts: 9

Original Poster
Rep: Reputation: 0
lackluster:

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?
 
Old 01-08-2003, 04:43 AM   #6
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 50
This might help a little more:
http://www.perl.com/pub/q/documentation
 
  


Reply



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
Cant Run Perl from VIM! simsjr Programming 6 04-07-2005 04:16 PM
vim: Piping through multiple external commands tragos Linux - Software 2 03-19-2005 01:09 PM
[Perl] brainstorming with pipes & commands patator Programming 3 06-25-2004 04:17 AM
2 Questions: java calling system commands? PERL vs Java? randomx Programming 28 11-28-2003 08:24 PM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration