Changing path in many files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Changing path in many files
# 1  
Old 04-08-2014
Changing path in many files

I have many html files in a directory tree and want to change the a path declaration within the files.

Files will look as below

I want to remove "geopdf/" so I get as example

Code:
href=../../../geo1937/geo02n01/geo0201r00010016.pdf

rather than keeping the entry as

Code:
href=../../../geopdf/geo1937/geo02n01/geo0201r00010016.pdf

I have tried the following awk command, the result being incorrect

Code:
awk -v s="..geopdf/" -v d="/" '{gsub(s,d); print}' /home/chrisd/Desktop/geo1937/geo02n04.html

Code:
<html>
<head>
<title>Vol. 2, No. 1 - 1937</title>
<script language=javascript>

<!--
function goback() {
        history.back();
}
//-->

</script>
</head>
<body bgcolor=#ffffff text=#000000 link=#996600 vlink=#29294a alink=#ff0000 onload=javascript:top.setissue('geo1937/geo02n01')>
<font face="arial,helvetica, sans-serif">
<TABLE align=center BORDER=0 CELLPADDING=10 CELLSPACING=0 WIDTH=95%>
<TR>
<TD ALIGN=LEFT>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR>

<TD ALIGN="LEFT" VALIGN="TOP">
<img src=../../images/geo.gif>
</TD>
<TD ALIGN="RIGHT" WIDTH="64" VALIGN="TOP"><A HREF="javascript:goback()" onMouseOver="window.status='Back to Previous Document'; return true;"><img src=../../images/segback.gif WIDTH="64" HEIGHT="30" BORDER="0" ALT="Back to previous document"></A></TD>
</TR>
</TABLE>
</TD>
</TR>
<TR>
     <TD ALIGN="LEFT">
<TABLE WIDTH=100% CELLPADDING="10" CELLSPACING="0">


<TD VALIGN="TOP">
<font FACE="Arial, Helvetica, sans-serif" SIZE="3">
<font SIZE="4"><B>Vol. 2, No. 1
<BR>1937</B></font>
<p><br>
<font FACE=arial><b>THE AMOUNT AND DISTRIBUTION OF SEISMIC AND GRAVITY EXPLORATION IN THE GULF COAST THROUGH 1936</b></font> <font size=2>(1-16)</font><br>
E. E. Rosaire; K. Ransone<br><a href=../../abstracts/geo1937/geo02n01/geo0201r00010016.html>Abstract</a> | <a href=../../../geopdf/geo1937/geo02n01/geo0201r00010016.pdf>PDF</a><p>

<font FACE=arial><b>A RESEARCH LIBRARY IN THE GEOPHYSICAL FIELD</b></font> <font size=2>(17-20)</font><br>
James B. Macelwane, S.J.<br><a href=../../abstracts/geo1937/geo02n01/geo0201r00170020.html>Abstract</a> | <a href=../../../geopdf/geo1937/geo02n01/geo0201r00170020.pdf>PDF</a><p>

<font FACE=arial><b>GRAVITATIONAL SURVEYING WITH THE GRAVITY-METER</b></font> <font size=2>(21-32)</font><br>
L. M. Mott-Smith<br><a href=../../abstracts/geo1937/geo02n01/geo0201r00210032.html>Abstract</a> | <a href=../../../geopdf/geo1937/geo02n01/geo0201r00210032.pdf>PDF</a><p>

<font FACE=arial><b>THE EFFECT OF MOISTURE ON THE DIRECT CURRENT RESISTIVITIES OF OIL SANDS AND ROCKS</b></font> <font size=2>(33-54)</font><br>
J. J. Jakosky; R. H. Hopper<br><a href=../../abstracts/geo1937/geo02n01/geo0201r00330054.html>Abstract</a> | <a href=../../../geopdf/geo1937/geo02n01/geo0201r00330054.pdf>PDF</a><p>

<font FACE=arial><b>On: "THE EFFECT OF MOISTURE ON THE DIRECT CURRENT RESISTIVITIES OF OIL SANDS AND ROCKS"</b></font> <font size=2>(54-55)</font><br>
R. D. Wyckoff<br><a href=../../abstracts/geo1937/geo02n01/geo0201r00540055.html>Abstract</a> | <a href=../../../geopdf/geo1937/geo02n01/geo0201r00540055.pdf>PDF</a><p>

<font FACE=arial><b>ABNORMAL VELOCITIES IN SEDIMENTARY BEDS IN EASTERN UTAH</b></font> <font size=2>(56-62)</font><br>
A. L. Smith; John H. Wilson<br><a href=../../abstracts/geo1937/geo02n01/geo0201r00560062.html>Abstract</a> | <a href=../../../geopdf/geo1937/geo02n01/geo0201r00560062.pdf>PDF</a><p>

</table>
</table>
</body></html>

---------- Post updated at 06:11 AM ---------- Previous update was at 06:07 AM ----------

This command seems to work. Can someone confirm this will work on all my files please.

Code:
awk -v s="geopdf/" -v d="" '{gsub(s,d); print}' /home/chrisd/Desktop/geo1937/geo02n01.html

# 2  
Old 04-08-2014
It would be safer to use:
Code:
awk -v s="/geopdf/" -v d="/" '{gsub(s,d); print}' /home/chrisd/Desktop/geo1937/geo02n01.html

in case other directory names ending in "geopdf" could appear in your data.
This User Gave Thanks to Don Cragun For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Convert Relative path to Absolute path, without changing directory to the file location.

Hello, I am creating a file with all the source folders included in my git branch, when i grep for the used source, i found source included as relative path instead of absolute path, how can convert relative path to absolute path without changing directory to that folder and using readlink -f ? ... (4 Replies)
Discussion started by: Sekhar419
4 Replies

2. UNIX for Advanced & Expert Users

Changing single path NIC to a teamed connection in same subnet

Dear all, I have a remote CentOS7 server that has two network cards. Each card has four ports and port one of card one was defined with the IP address assigned to the server. So far, so good and it's been working for over a year. We have now got cables sorted out so there are four paths... (4 Replies)
Discussion started by: rbatte1
4 Replies

3. Shell Programming and Scripting

Moving files from parent path to multiple child path using bash in efficient way

Hi All, Can you please provide some pointers to move files from Base path to multiple paths in efficient way.Folder Structure is already created. /Path/AdminUser/User1/1111/Reports/aaa.txt to /Path/User1/1111/Reports/aaa.txt /Path/AdminUser/User1/2222/Reports/bbb.txt to... (6 Replies)
Discussion started by: karthikgv417
6 Replies

4. UNIX for Dummies Questions & Answers

Changing Path Variable

Blank Blank Blank (11 Replies)
Discussion started by: pvibien
11 Replies

5. Shell Programming and Scripting

Changing the Login Path

Hi frnds! i m installing a software named 'Gamit' by using bash. bt i recieved the follwoing error: .. removing any existing Makefiles or archive files from libraries directories /root/Documents/ISP/Gamit_10.4/com/rmfresh: Permission denied. .. removing any existing Makefiles or... (1 Reply)
Discussion started by: Engr. Shoaib
1 Replies

6. Shell Programming and Scripting

Changing the path

Hi , Iam changing the path in weblogic from /opt/user/shared/mydomain to /opt/users/shared/multidomain i have to change the below configuration files by using scripting am using for loop and sed to change the below files. for i in ${b}startWebLogic.sh... (1 Reply)
Discussion started by: sam1226
1 Replies

7. Shell Programming and Scripting

List all the files in the present path and Folders and subfolders files also

Hi, I need a script/command to list out all the files in current path and also the files in folder and subfolders. Ex: My files are like below $ ls -lrt total 8 -rw-r--r-- 1 abc users 419 May 25 10:27 abcd.xml drwxr-xr-x 3 abc users 4096 May 25 10:28 TEST $ Under TEST, there are... (2 Replies)
Discussion started by: divya bandipotu
2 Replies

8. Solaris

Changing of syslog file path instead of /var/log directory

Hi Please let me know how can we change the syslog file path from /var/log to /a directory in solaris Regards (4 Replies)
Discussion started by: amity
4 Replies

9. Shell Programming and Scripting

Executing Commands From Non-Standard Path (Changing user's PATH secretely???)

Hi: I have a requirement as below: I have some standard Unix commands modified and kept them in a directory say /usr/clsh/bin. For example I have a script named "ls" kept here which is modified version of "ls" (say it always gives long listing i.e. ls -l). When any user logs on and types... (2 Replies)
Discussion started by: ramesh_samane
2 Replies

10. Shell Programming and Scripting

How to change prompt color when changing path

Hi all, Can you tell me how to change the prompt color (only the path part) when I chnange directory with "cd"? I use the sequence below in ".bashrc" (Solaris 8) to change my prompt colors and I'd like to modify it to change the path color when I cange directory. PSC() { echo -ne "\"; }... (0 Replies)
Discussion started by: majormark
0 Replies
Login or Register to Ask a Question