append shit at end of line..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xxweekxx
    Confirmed User
    • Oct 2002
    • 6780

    #1

    append shit at end of line..

    anyone know of a script that will add shit to end of line,

    example if my notepad file is:

    1.1.1.1
    2.2.2.2

    i want it to be'

    1.1.1.1:80
    2.2.2.2:80

    anyone know?
    _________________
    I am the best
  • GrouchyAdmin
    Now choke yourself!
    • Apr 2006
    • 12085

    #2
    for n in `cat file`; do echo $n":lolsox" >> file.new; done

    Comment

    • GrouchyAdmin
      Now choke yourself!
      • Apr 2006
      • 12085

      #3
      sed 's/$/:lolsox/g' file > file.new

      Comment

      • Angry Jew Cat - Banned for Life
        (felis madjewicus)
        • Jul 2006
        • 20368

        #4
        someone who writes code daily should be able to whip something up in a couple minutes.

        Comment

        • GrouchyAdmin
          Now choke yourself!
          • Apr 2006
          • 12085

          #5
          awk ' { print $0":lolsox" } ' file > file.new

          Comment

          • BestXXXPorn
            Confirmed User
            • Jun 2009
            • 2277

            #6
            Or if you have a text editor and want to do it manually ...

            Find replace \n with :80\n

            \n is newline btw :P Some editors might want you to use ^n or something...
            ICQ: 258-202-811 | Email: eric{at}bestxxxporn.com

            Comment

            • GrouchyAdmin
              Now choke yourself!
              • Apr 2006
              • 12085

              #7
              Code:
              <?php // PHP4monkeyz
              $l = file('file');
              $n='';
              foreach ($l as $ln => $line) {
                  echo "Doin da line #{$ln}.\n";
                  $n .= $line."lolsox";
              }
              $f = @fopen('file.new, 'w');
              if (!$f) {
                die("I can't be writin no files mothafuccka.\n");
              } else {
               $b = fwrite($f, $data);
               fclose($f);
               echo "I done writ ". ($b/1024) . "kB, yo.\n";
              }
              ?>

              Comment

              • seeandsee
                Check SIG!
                • Mar 2006
                • 50945

                #8
                Originally posted by GrouchyAdmin
                awk ' { print $0":lolsox" } ' file > file.new
                lol SOX
                BUY MY SIG - 50$/Year

                Contact here

                Comment

                • xxweekxx
                  Confirmed User
                  • Oct 2002
                  • 6780

                  #9
                  Originally posted by GrouchyAdmin
                  Code:
                  <?php // PHP4monkeyz
                  $l = file('file');
                  $n='';
                  foreach ($l as $ln => $line) {
                      echo "Doin da line #{$ln}.\n";
                      $n .= $line."lolsox";
                  }
                  $f = @fopen('file.new, 'w');
                  if (!$f) {
                    die("I can't be writin no files mothafuccka.\n");
                  } else {
                   $b = fwrite($f, $data);
                   fclose($f);
                   echo "I done writ ". ($b/1024) . "kB, yo.\n";
                  }
                  ?>

                  tried that..

                  get

                  Parse error: syntax error, unexpected T_STRING in /home/psmail/public_html/safelocals.com/test/append.php on line 8
                  _________________
                  I am the best

                  Comment

                  • GrouchyAdmin
                    Now choke yourself!
                    • Apr 2006
                    • 12085

                    #10
                    Originally posted by xxweekxx
                    tried that..
                    That one was the joke.

                    This one works though:
                    Code:
                    <?php // PHP4monkeyz
                    $l = file('file');
                    $n='';
                    foreach ($l as $ln => $line) {
                        echo "Doin da line #{$ln}.\n";
                        $n .= rtrim($line) . "lolsox" . "\n";
                    }
                    $f = fopen('file.new', 'w');
                    if (!$f) {
                      die("I can't be writin no files mothafuccka.\n");
                    } else {
                     $b = fwrite($f, $n);
                     fclose($f);
                     echo "I done writ ". ($b/1024) . "kB, yo.\n";
                    }
                    ?>
                    This is still godawful code, but it works. Again, It was a joke.
                    Last edited by GrouchyAdmin; 08-29-2009, 04:38 PM. Reason: It's just really ugly.

                    Comment

                    • GrouchyAdmin
                      Now choke yourself!
                      • Apr 2006
                      • 12085

                      #11
                      Just for the hell of it, here's a PHP 4.4+ only inelegant hack:
                      Code:
                      <?php echo file_put_contents('file.new', str_replace("\n", "lolsox\n", file_get_contents('file')))?"Worked\n":"Didn't worked\n";?>
                      Really, though, everything above works in exactly the same way - find 'end of line' and replace (append) to. Semantically, it's slightly different, but doesn't matter.

                      Comment

                      Working...