Word Manipulation

Hello,

I have a file with words on each line:

example:

word1
word2
word3
etc.


I'm looking for a way to output them in the following format

$i=="word1" || $i=="word2"  || $i=="word3"  || $i=="etc"

Thank you
faithless1Asked:
Who is Participating?
 
tel2Commented:
Hi faithfull1,

How's this:
    perl -0ne 's/^(.*)$/\$i=="$1"/mg;s/\n\$/ || \$/g;print' infile.txt
0
 
a1jCommented:
#!/usr/bin/perl

my $tmp=<>;
print '$tmp=="' . $tmp . "'";
while (<>) {
   chomp;
   print '|| $i=="' . $_ . "'";
}
##################
usage: cat infile.txt | ./script > outfile.txt
0
 
a1jCommented:
errr ... probably need to insert "chomp $tmp;" before "print $tmp"
0
 
tel2Commented:
...or written as a traditional script:
    #!/usr/bin/perl
    undef $/;
    $_ = <>;
    s/^(.*)$/\$i=="$1"/mg;
    s/\n\$/ || \$/g;
    print;

Usage: ./myscript.pl <data.in
0
 
faithless1Author Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.