GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   append shit at end of line.. (https://gfy.com/showthread.php?t=924647)

xxweekxx 08-29-2009 04:59 PM

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?

GrouchyAdmin 08-29-2009 05:09 PM

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

GrouchyAdmin 08-29-2009 05:10 PM

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

Angry Jew Cat - Banned for Life 08-29-2009 05:10 PM

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

GrouchyAdmin 08-29-2009 05:11 PM

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

BestXXXPorn 08-29-2009 05:13 PM

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...

GrouchyAdmin 08-29-2009 05:17 PM

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";
}
?>


seeandsee 08-29-2009 05:20 PM

Quote:

Originally Posted by GrouchyAdmin (Post 16252122)
awk ' { print $0":lolsox" } ' file > file.new

lol SOX :1orglaugh:1orglaugh

xxweekxx 08-29-2009 05:32 PM

Quote:

Originally Posted by GrouchyAdmin (Post 16252146)
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

GrouchyAdmin 08-29-2009 05:37 PM

Quote:

Originally Posted by xxweekxx (Post 16252204)
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. :)

GrouchyAdmin 08-29-2009 05:50 PM

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.


All times are GMT -7. The time now is 12:50 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123