![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Perl Search and replace entire line | insania | Shell Programming and Scripting | 1 | 05-22-2008 06:45 PM |
| Search and replace in Perl | jyoung | Shell Programming and Scripting | 2 | 04-22-2008 01:05 PM |
| Perl: Search for string on line then search and replace text | Crypto | Shell Programming and Scripting | 4 | 01-04-2008 10:24 AM |
| perl search and replace pairs | umen | Shell Programming and Scripting | 1 | 07-30-2006 11:37 AM |
| Global search ok...but replace? | alan | UNIX for Dummies Questions & Answers | 0 | 03-25-2004 04:22 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
I have a file where the rows correspond to individuals and the columns are about 106 variables. Each variable is coded as either ACGT, and "missing" is coded as blank. This is a tab delimited file. I'm trying to replace all blanks (" ") with 0. The simple script I have is only replacing some of the blanks. Please help me figure out what's wrong with the script, so that every blank could be replaced by zero. Thanks!!!!
#!/usr/local/bin/perl print "What file would you like to edit?"; $filename= <STDIN>; open (TEXT, "$filename") || die "Can't open"; open (OUT, ">gd_53d.out" || die "Can't Open"); $var = " "; while ($var ne "") { $var = <TEXT>; if ($var eq "\t\t") { print OUT "\t\t"; next; } $var =~s/\t\t/\t0\t/gi; print OUT $var; } close TEXT; close OUT; exit; |
|
||||
|
doesn't work.
example format of file: id a1 a2 1 A B 2 A B 3 4 A B Even the following perl code only replaces some of the blanks with 0. #!/usr/local/bin/perl open (TEXT, "gd_53.txt" || die "Can't open"); open (OUT, ">gd_53b.out" || die "Can't Open"); undef($/); $var = <TEXT>; $var =~ s/\t\t/\t0\t/g; print OUT $var; exit; thanks! |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|