11-20-2004
grep & sed question
I'm trying to write a bash script to perform a tedious task, but I have no experience and hardly any knowledge so I've been having a rough time with it.
I'm on Mac OS X, and I want a script to do the following:
I have a directory that has about 200 sudirectories. In each of these directories, there are a number of html files that each include a relative link to an image.
What I want to do is create one html file that contains all the img tags of all the html files in all the sudirectories. I would also like to turn all the relative links into absolute ones (meaning: I want each src attribute to contain the full path on my system of the html file -and image, they are in the same directory-).
I've been at it with sed, but one of the problems seems to be that some of the html files don't have regular UNIX line endings, so it's kind of hard for me to extract just those line with img files (I get the full files), let alone img tags.
What I've been toying with is the following (where you'll see that I try to put some line endings back where I think they'd be useful - though for some reason it doesn't work as expected):
#!/bin/bash
for pic in ./advanced/*/image??.html
do
grep img $pic | sed "s/img/img\
/" | cat >> images.html
done
This script doesn't address the absolute link problem yet.
Any help would be greatly appreciated.
Last edited by der Kopf; 11-20-2004 at 05:00 AM..
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hello,
I am new to shell scripting.
I have a input file: Few lines of the input file has the following.
/a0012/abcd12/abcd12
/a0003/xyzab1/lmno123
/a0006/pqrst1/abcde12
In my output file, I only need to get anything that is between the first and second '/' of each line: exampple:... (6 Replies)
Discussion started by: hemangjani
6 Replies
2. Shell Programming and Scripting
i am still confusing on how to use sed, grep and awk if the input is not a file but a variable.
such as:
a="hello world"
b="how are you"
c="best wish to you"
d="222,333,444"
what if i want to check which variable $a,$b,$c,$d have contain "you"
what if i want to replace the word "you"... (9 Replies)
Discussion started by: 3Gmobile
9 Replies
3. UNIX for Dummies Questions & Answers
Hi all,
I know this question has probably been answered before, but I am struggling with this problem, even after googling a million pages.
In a file named rdmt.conf
I need a single character replaced, the number in the line below
CUR_OC4J_ID=1
It will always appear after... (3 Replies)
Discussion started by: Mike AAA
3 Replies
4. UNIX for Dummies Questions & Answers
Hi
I am having a 'grep' headache
Here is the contents of my file:
(PBZ,CP,(((ME,PBZ,BtM),ON),((ME,((PBZ,DG),(CW9,PG11))),CW9,TS2,RT1)))
I would like to count out how many times 'PBZ' occurs and then place that number in the line above
3... (8 Replies)
Discussion started by: cavanac2
8 Replies
5. Shell Programming and Scripting
On one of my servers, it appears that a bunch of html files got the following code added to it...
I was going to try to remove this line using grep & sed... as sample
grep -lr -e 'apples' *.html | xargs sed -i 's/apples/oranges/g'
I can get the grep portion to work...
grep "<script... (7 Replies)
Discussion started by: djlane
7 Replies
6. Shell Programming and Scripting
hi everybody
i have this script and it work's if i use a single variable in grep, but when i put $searchterm_ the script stops work
i have a problem too in sed, because i don't know how i can search and replace more than one item, in this case is >>> $searchterm/$replaceterm and... (4 Replies)
Discussion started by: felito
4 Replies
7. Shell Programming and Scripting
I'm new using Unix commands in applescript. The following script you choose different folders with PDfs, get file count of PDfs on chosen folders, & write the results in text file.
set target_folder to choose folder with prompt "Choose target folders containing only PDFs to count files" with... (0 Replies)
Discussion started by: nellbern
0 Replies
8. Shell Programming and Scripting
I have the following line of code that works wonders. I just don't completely understand it as I am just starting to learn regex. Can you help me understand exactly what is happening here?
find . -type f | grep -v '^\.$' | sed 's!\.\/!!' (4 Replies)
Discussion started by: trogdortheburni
4 Replies
9. Shell Programming and Scripting
Hi All,
Facing an issue with grep & sed
I have logs as below:
gsc_1_20121121.log:2012-11-21 10:09:13,143 INFO - fmsspace.1 ProcessNewOrderSingleRequest: Result - ProcessNewOrderSingleBatchResultDTO - success:true,newOrderSingleBatchResults:ProcessNewOrderSingleResultDTO -... (13 Replies)
Discussion started by: irfanmemon
13 Replies
10. Shell Programming and Scripting
Hi All,
I have a file with following sample data. I am also attaching the file.
(Est) (Est) Jobs Sch
Workstation Job Stream SchedTime State Pr Start Elapse # OK Lim
POOL #ACR_BILLING 0005 08/15 ... (2 Replies)
Discussion started by: Kevin Tivoli
2 Replies