Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi, I am stuck on the following issue with awk and need help. I currently have data that looks like this:
Directory of /home/admin/slap/test
06/09/2009 08:15 AM 954,880 bin.fla
02/09/2009 09:48 AM 173,905 bin.swf
03/23/2009 11:04 AM 2,168 bin.xml
06/09/2009 08:15 AM 830,464 dnd.fla
02/05/2009 12:47 PM 175,001 dnd.swf
02/05/2009 11:13 AM 1,835 dnd.xml
06/09/2009 08:15 AM 755,712 mcq.fla
06/09/2009 08:15 AM 46,843 mcq.swf
06/09/2009 08:15 AM 2,706 mcq.xml
Directory of /home/admin/slap/test2
06/09/2009 08:16 AM 954,880 bin.fla2
02/09/2009 09:47 AM 173,905 bin.swf2
03/23/2009 11:04 AM 2,168 bin.xml2
06/09/2009 08:17 AM 830,464 dnd.fla2
02/05/2009 12:48 PM 175,001 dnd.swf2
02/05/2009 11:10 AM 1,835 dnd.xml2
06/09/2009 08:16 AM 755,712 mcq.fla2
06/09/2009 08:14 AM 46,843 mcq.swf2
06/09/2009 08:12 AM 2,706 mcq.xml2
I need to somehow run through this file and extract out "Directory of /home/admin/slap/test" and append it to each file in the 5th field.
So the end result would be something like:
Directory of /home/admin/slap/test/bin.fla
Directory of /home/admin/slap/test/bin.swf
Directory of /home/admin/slap/test/bin.xml
etc....
for each block of files. So the next block would be
Directory of /home/admin/slap/test2/bin.fla2
Directory of /home/admin/slap/test2/bin.swf2
Directory of /home/admin/slap/test2/bin.xml2
Not sure if awk would be the right tool or if this is even possible. Any advice would be great. This was a originally a directory list of all files and we need to somehow reconstruct back to a full directory listing.
This is what I have tried so far, just confused on how to append to each file in each block.
#!bin/awk -f
#
/Directory of.*/ {
x = $3 #Set field $ into variable x
print $x
}
Location: Fleury-les-Aubrais, 120 km south of Paris
Distribution: Devuan, Debian, Mandrake, Freeduc (the one I used to work on), Slackware, MacOS X
Posts: 251
Rep:
A way to begin
Something I've made at work:
#!/usr/bin/awk -f
BEGIN {
print "Starting and searching for ",searchingfor
workingdirectory="non"
}
#If we find "Directory of", we finished the directory
/Directory of/ { workingdirectory="non" }
#We print the result if we are in a directory
{ currentline=$0
if (currentline ~ searchingfor && workingdirectory !="none") { print workingdirectory,$0 } }
#Each time we find a directory, we store its name in workingdirectory
/Directory of/ { workingdirectory=$4 }
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.