Created
April 25, 2014 00:26
-
-
Save privatehosting/11274108 to your computer and use it in GitHub Desktop.
Zeilenscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php -q | |
<?php | |
if(isset($argv[0]) && isset($argv[1])) | |
{ | |
$opt_use = 0; | |
$dir_use = 0; | |
if(file_exists($argv[1])) { | |
$opt_use = 1; | |
$dir_use = ($argv[1]); | |
} elseif(file_exists(getcwd().$argv[1])) { | |
$opt_use = 2; | |
$dir_use = (getcwd().$argv[1]); | |
} else die("Datei Exitiert nicht\n"); | |
$datei = $dir_use; | |
$file = file($datei); | |
if(isset($argv[2]) && isset($argv[2]) > 250 || empty($argv[2]) && count($file) >= 500) | |
{ | |
echo "Die Datei hat mehr als 500 Zeilen! Soll PHP Weitermachen? (y): "; | |
if($stdin = fopen("php://stdin","r")) | |
{ | |
$input = trim(fgets($stdin)); | |
fclose($stdin); | |
} | |
if($input!="y") die("PHP-Script Wurde Abgebrochen!\n"); | |
} | |
if(empty($argv[2])) | |
{ | |
for($n=1; $n <= count($file); $n++) | |
{ | |
if(isset($file[$n]) && strlen($file[$n]) >= 1) echo "Zeile: ".$n." \n ".$file[$n].""; | |
} | |
} else | |
{ | |
for($n=count($file)-$argv[2]; $n <= count($file); $n++) | |
{ | |
if(isset($file[$n]) && strlen($file[$n]) >= 1) echo "Zeile: ".$n." \n ".$file[$n].""; | |
} | |
} | |
} else { | |
echo "Agument Falsch oder exitiert so nicht!"; | |
for($n=0; $n <= count($argv); $n++) | |
{ | |
if(isset($argv[$n])) echo "\nArgument ".$n." ist ".$argv[$n].""; | |
} | |
echo "\n"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment