=== Emulate linux find via linux ls -R === #!/bin/sed -n # Emulate linux find via linux ls -R # useful when we have to connect to some host wich does not have # 'find' and we want to make an script to get all files. # I use this to get a list of files to pull from my android device. # # If you run sed from linux, maybe you have to change ".$" into "$". #".$" is used to remove spurious \r characters in ms-windows # (sed for windows does not understand \r or \n). # # # Use sed -n to run this script # # # IN SPANISH: #Convertir la salida de ls -R en una salida parecida a la de find: #(Android no tiene find, solo ls -R) # (este script elimina los \r del final de lĂ­nea; puede ser necesario # modificarlo si se usa en unix) /[/]/{ s/\(^.*:\).*$/\1/ h } /[/]/!{ s/^.*$/##FIELD##&##DLEIF##/g G s/##FIELD##\(.*\).##DLEIF##..\(.*\):.*$/\"\2\/\1\"/g p } #Explanation: # If a line including "/" and ending with ":" is found, it is inserted into hold space. # Then, if a line not including "/" is found: # Line is converted into ##FIELD####DLEIF## # The hold line is appended to it.b # The text between ##FIELD## and ##DLEIF## is used as field 1, discarding last char (probably a carriage return). # The text after ##DLEIF## up to the ":", and excluding it, is used as second field. # The line is substituted by field2\field1