Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, I am new to UNIX (Korn Shell

Status
Not open for further replies.

RVSachin

Technical User
Nov 12, 2001
77
IN
Hi,

I am new to UNIX (Korn Shell).
Would some one tell me the way to meet my specs?

I will be having a folder by name 'file' and within that a folder as file_01.
This folder will have a file by name file_01.xyz.
This file will have, among other things, a part of line which would read as file_01.abc.
And another line as file_01.txt.

Now, I need a script which would:

1. Create a folder by whatever name I request it to do. Let's say myfile.
2. Create sub-directory myfile_01.
3. Copy the contents of file_01.xyz into the sub folder.
4. Change the string file_01.abc in the file to myfile_01.abc.
5. Change the string file_01.txt in the file to myfile_01.txt.

Note that, I shall be doing this on multiple files.
I was able to create the sub-folders and copy the .xyz files, but was not able to get into the file and change the string names in those files.

Would some one help me in solving this?

Thanks,
RV
 
You can change the contents of any file with sed
Look in the man pages for sed.
In the example above, you'd do something like :
sed 's/file_01\.abc/myfile_01\.abc/' file_01.xyz > temp_file
mv temp_file file_01.xyz

the \ before a full-stop(period) means sed accepts it as a full-stop(period), not a 'any-character' place.
HTH

Dickie Bird (:)-)))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top