Advertisement
B47CHGURU

Text adder and replacer

Jul 23rd, 2011
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.95 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. ##########################################################################################
  3. # Coded by B47CHGURU on 24-07-2011  For Kishan Bhai..!!                                  #
  4. # Updated on 11-08-2011                                                                  #
  5. #if any bugs are found ...plz do inform me at [email protected]                   #
  6. #----------------------------------------------------------------------------------------#
  7. #To all script kiddies..... changing the "made by" headers wont make you the coder...!!  #
  8. #Respect the coderz..!!!                                                                 #
  9. ##########################################################################################
  10.  
  11.  print ("#######################################################\n");
  12.  
  13.  print ("    Welcome to B47CH GURU's Text Adder or Replacer!\n");
  14.  
  15.  print ("########################################################\n\n");
  16.  
  17.  print " Do you want to remove blank lines in the process? (y/n)";
  18. my $remline=<STDIN>;
  19. chomp($remline);
  20. if ($remline =~ /y/){
  21. $linerem = 'y';
  22. } else {
  23. $linerem = 'n';
  24. }
  25. print " Do you want to add or replace\(a or r\)";
  26. my $option=<STDIN>;
  27. chomp($option);
  28. if ($option =~ /a/){
  29. adding();
  30. }
  31. if ($option =~ /r/){
  32. replace();
  33. }
  34.  
  35.  
  36. sub adding{
  37. print ' The path to your source file eg: list.txt> ';
  38. $list =<STDIN>;
  39. chomp($list);
  40. print " The path to the processed file> ";
  41. $loged =<STDIN>;
  42. chomp($loged);
  43. print " where you want to add, beginning or last \( b or l\)> ";
  44. $insert =<STDIN>;
  45. chomp($insert);
  46. print " the phrase you want to add> ";
  47. $adder =<STDIN>;
  48. chomp($adder);
  49. open FILE, "+>$loged" or die $!;
  50. open (SOURCE, "<$list") || die "[-] Can't open the list !";
  51. @PASSWORDS = <SOURCE>;
  52. close SOURCE;
  53. loop: foreach $P(@PASSWORDS) {
  54. chomp($P);
  55. $P = trim($P);
  56. if ($linerem =~ /y/){
  57. if ($P =~ m/^$/){
  58.  
  59. next loop;
  60.  
  61. }
  62. }
  63. if ($insert =~ /b/){
  64. $P = $adder . $P;
  65. print FILE "$P\n";
  66. print ("$P \n");
  67. }
  68. if ($insert =~ /l/){
  69. $P = $P . $adder;
  70. print FILE "$P\n";
  71. print ("$P \n");
  72. }
  73.  
  74. }
  75. close FILE;
  76. }
  77. sub replace{
  78. print ' The path to your source file eg: list.txt> ';
  79. $list =<STDIN>;
  80. chomp($list);
  81. print " The path to the processed file> ";
  82. $loged =<STDIN>;
  83. chomp($loged);
  84. print " The phrase you want to find> ";
  85. $find =<STDIN>;
  86. chomp($find);
  87. print " The phrase to be replaced with the found> ";
  88. $replace =<STDIN>;
  89. chomp($replace);
  90. open FILE, "+>$loged" or die $!;
  91. open (SOURCE, "<$list") || die "[-] Can't open the list !";
  92. @PASSWORDS = <SOURCE>;
  93. close SOURCE;
  94. loop2: foreach $P(@PASSWORDS) {
  95. chomp($P);
  96. $P = trim($P);
  97. if ($linerem =~ /y/){
  98. if ($P =~ m/^$/){
  99.  
  100. next loop2;
  101.  
  102. }
  103. }
  104. if ($P =~ m/$find/sim) {
  105.  $P =~ s/$find/$replace/g;
  106.  print FILE "$P\n";
  107. print ("$P \n");
  108. } else {
  109. print FILE "$P\n";
  110. print ("$P \n");
  111.   next loop2;
  112. }
  113.  
  114. }
  115. close FILE;
  116. }
  117.  
  118. sub trim{
  119.   $string = shift;
  120.   $string =~ s/^\s+//;            
  121.   $string =~ s/\s+$//;
  122.   return $string;        
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement