Print lines between a regExp & a blank line

Hi,

I have a file, say files_list, as below (o/p of ls -R cmd)

 
$ cat files_list
/remote/dir/path/to/file:
sub-dir1
sub-dir2
sub-dir3
...
 
/remote/dir/path/to/file/sub-dir1:
remote_file1.csv.tgz
<blank line 1>
/remote/dir/path/to/file/sub-dir2:
remote_file2.csv.tgz
<blank line 2>
/remote/dir/path/to/file/sub-dir3:
remote_file3.csv.tgz
<blank line 3>
....
 

I want to read this file in a loop and produce an o/p like

 
Output file
-----------
/remote/dir/path/to/file/sub-dir1/remote_file1.csv.tgz
/remote/dir/path/to/file/sub-dir2/remote_file2.csv.tgz
/remote/dir/path/to/file/sub-dir3/remote_file3.csv.tgz
.....

I was able to extract all sub-dir in a file, say sub_dir_file

 
$ cat sub_dir_file
sub-dir1
sub-dir2
sub-dir3

I thought of looping through the list of sub-dir and using below sed between

 
for line in cat sub_dir_file
do
sed -n '/remote/dir/path/$line, <blank line of this block i.e. blank line1>/p' files_list
.........more formatting..........
done

Am I on the right path or can you please correct the sed /from/,/to pattern/p command?

-dips

please give this a try

ls -R | gawk ' /:$/ { dir=gensub(/^(.*):$/, "\\1/", "g"); next; } { print dir $NF }' 

You are on the right path, however, note that a slash is a metacharacter for sed. You have to escape your path slashes with backslash. Like:

sed -n '/\path\/to\/somewhere/,/^$/p' files_list

Yeah, and the /^$/ is an empty line. A pattern /^[ \t]*$/ would be even better, if you suspect there may be some whitespace chars hidden.

However, isn't this too much work? Have you looked at find(1) yet?

Try

find /remote/dir/path/to/file -type f

Similar awk solution..

ls -R | awk -F'[ :]' '$0~/^[.]*\/.*/ {r=$1;next} r!="" && $0!="" {print r "/" $0}'