remove space, tab, newline etc.. from a text file
Collapse
X
-
you want a character class:
you don't need \t because its included in \sCode:$string =~ s/[\n\r\s]+//g;
Leave a comment:
-
for the regexp to work you need to make sure it has a VAR with a string.
Code:#!/usr/bin/perl local $/=undef; open(FILE, "test.fa") || die ("Error\n"); $string = <FILE>; $string =~ s/\n\r\t\s//g; print "$string";Leave a comment:
-
remove space, tab, newline etc.. from a text file
I am trying to remove all white spaces, tabs, newline, carriage return etc.. from a text file to make it as a one continous string. But the following code doesnot work. The file size is relatively smaller and hence I didn't use FILE::slurp. Please let me know the problem. Thanks.
Code:#!/usr/bin/perl local $/=undef; open(FILE, "test.fa") || die ("Error\n"); $string = <FILE>; $corrected_string =~ s/\n\r\t\s//g; print "$corrected_string";
Leave a comment: