remove space, tab, newline etc.. from a text file

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • ghostdog74
    replied
    you can use re extension [:cntrl:]

    Leave a comment:


  • lilly07
    replied
    oops! I didn't realise the var component. Thanks.

    Leave a comment:


  • KevinADC
    replied
    you want a character class:

    Code:
    $string =~ s/[\n\r\s]+//g;
    you don't need \t because its included in \s

    Leave a comment:


  • Icecrack
    replied
    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:


  • lilly07
    started a topic remove space, tab, newline etc.. from a text file

    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";
Working...