Solved

Modify file with directory structure details

Posted on 2011-09-06
3
236 Views
Last Modified: 2012-05-12
I need to take an existing file, an rpm spec file, and insert a list of files at a specific point.  The spec file will have something like this as the demarcation of where the file list needs to be inserted:
%file
The script needs to take a directory and recursively identify all files under that directory and write each file, and its path, on a separate line in the rmp spec file.

What would be the best way to handle this?



0
Comment
Question by:jkavx
  • 2
3 Comments
 
LVL 2

Expert Comment

by:nukeme369
ID: 36493138
#!/bin/bash
workingdir=`pwd`
for filelist in *
do echo $workingdir"/"$filelist >>/tmp/rpmspecfile
done




Fairly self explanatory, but I'll walk through it.

Variable named workingdir is defined with the current directory as its data.
for loop - looping through each file in current directory.  
each file has the following happen:
the $workingdir variable is echoed, with a trailing /  then the current file is written to /tmp/rpmspecfile.

Repeat for every file in the current dir.

0
 
LVL 2

Accepted Solution

by:
nukeme369 earned 500 total points
ID: 36493141
(the above is the script needed to generate the file list - working on the insert at %file part)
0
 

Author Closing Comment

by:jkavx
ID: 36517137
If you can work out the insert at the specific file location piece, please add a comment with the details.  Thx.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Fine Tune your automatic Updates for Ubuntu / Debian
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now