awk or sed command-line routine to solve this situation?
We hava data file which has entries in this format:
sap/base/parser/agent/wholeworld.cpp
These have to be converted into :
wholeworld.cpp|sap/base/parser/agent/
ie <filename>|<path>
This has to be done via command-line.
and we cannot do a hard-coded awk -F/ print{$NF "|" $0"/"$1... etc.},as the path-name length will be different all over.
How can this be done ?
Even a sed-based command-line solution will suffice(leaner the better!!!!)
Any help would be appreciated
# 1 Re: awk or sed command-line routine to solve this situation?
Well if you are talking about converting it to that format, and you want to use PHP, it is rather simple.
<?php
$string = "sap/base/parser/agent/wholeworld.cpp";
$file = str_replace("/", "", strrchr($string, "/"));
$path = str_replace($file, "", $string);
echo $ouput = $file . "|" . $path;
?>
...or if you want multiple output...
<?php
$string = array();
$string[0] = "sap/base/parser/agent/wholeworld.cpp";
$string[1] = "this/is/the/files/path/blah.cpp";
$string[2] = "here/you/go/hello.cpp";
foreach($string as $s){
$file = str_replace("/", "", strrchr($s, "/"));
$path = str_replace($file, "", $s);
echo $ouput = $file . "|" . $path;
echo "<br>";
}
?>