sed: transforming 'ls-laR' output into a list with absolute paths
Hello, this is my first post :)
First i would like to thank you all for answering other people questions because I've been able to learn from the forum a lot. I need your help with something. I have standard output from 'ls -laR /etc' command which looks like this: Code:
/etc/X11/xorg.conf.d: Code:
sed -e '/./!d' -e '/^total/d' -e '/\.$/d' -e 's/:$/\//' list.txt Code:
/etc/X11/xorg.conf.d/ Code:
-rw-r--r--. 1 root root 232 Apr 1 00:46 /etc/X11/xorg.conf.d/00-keyboard.conf How do I join(merge) filenames with corresponding absolute path to their parent directory? I know how to extract filenames using awk and get this: Code:
00-keyboard.conf |
your probably better off learning how to print with find. heres an e.g.:
http://www.linuxquestions.org/questi...1/#post5343834 |
That's a pretty big request, as there's no telling how many directories deep that the "ls -laR" command will go.
You can get the same output that you're going for with: find /etc -type f -exec ls -al {} \; That will give you what you're looking for, a directory listing of all the /etc files, and their complete path to root, and their full "ls -al" attributes, but for files only (not directories themselves, only their contents). If you want to include symbolic links, etc. as well as files - then I'd just get everything that's not a directory... find /etc ! -type d -exec ls -al {} \; |
Thanks guys. I forgot to say that I know "find", but it's not me whose generating input file in this form.
This kind of file is a snapshot of permissions from few years back and I need to compare it with current ACLs on the system. So still looking for an idea for converting this "ls -laR" kind of file to "find" like file. |
On your transformed sample
Code:
/etc/X11/xorg.conf.d/ Code:
awk '/^\//{x=$0;next}/[^/]/{print $1,$2,$3,$4,$5,$6,$7,$8,x $9}' |
OMG this is fantastic. Thank you! You have convinced me to learn awk :)
I need to be honest with you. I have not been just waiting for solution for 3 hours. I've been trying to solve this... and I did (to my surprise). Your code much better however. Anyway just for the record here's what I got: Code:
#!/bin/bash |
You could of course do all that clean-up work in awk as well, and not need the temp files.
Happy learning - awk is very flexible. Lots of knowledgeable people here to help when you run into brick walls. |
All times are GMT -5. The time now is 02:05 PM. |