×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How can i remove one line from file ???

How can i remove one line from file ???

How can i remove one line from file ???

(OP)
Hi !

I have a problem...

I have datafile separated with ¦ -sign.

kori.dat looks like that:

data1¦data1¦data1¦data1
data2¦data2¦data2¦data2
data3¦data3¦data3¦data3
data4¦data4¦data4¦data4

How can i remove data1¦data1¦data1¦data1 -line or data3¦data3¦data3¦data3 -line ????


Thanks!


RE: How can i remove one line from file ???

first save the line to a variable like $line. Then


$line =~ s/data1¦data1¦data1¦data1//;

This will substitute that line with nothing, thus making ur line disappear.

RE: How can i remove one line from file ???

This might be what you are looking for......
With the lines of your file in @lines.....

#!/usr/local/bin/perl

@lines = ( 'data1¦data1¦data1',
    'data2¦data1¦data1',
    'data3¦data1¦data1',
    'data4¦data1¦data1',
    'data5¦data1¦data1');

foreach $line (@lines) { print "$line\n"; }

$garbage = splice(@lines,2,1);
splice pulls the elements from the array
                                                                    starting on the third element and going
                                                                    and going 1 and returns the removed
                                                                    elements.  This example removes
                                                                    the 'data3' line.

print "\n\n";
foreach $line (@lines) { print "$line\n"; }

print "\n\n$garbage\n";




keep the rudder amid ship and beware the odd typo

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close