Re: Yahoo! Groups: Welcome to sed-users. Visit today!
Cameron Simpson <[email protected]>
| Newsgroups | gmane.editors.sed.user |
|---|---|
| Message-ID | <[email protected]> |
On 27Apr2012 10:23, Luigi Assom <[email protected]> wrote: | I was finally able to write this syntax which worked for me: | first I extract url and I save it on a second file: | sed -n -e 's/\(<a[^h]*href="\)\([^"]*\)"\([^>]*>\)/\2/g; p' | /Users/gg4u/prova4.txt > /Users/gg4u/prova5.txt | | then I clean out all others html tag and save it on a third file: | sed -e 's/<[^>]*>//g' /Users/gg4u/prova5.txt > /Users/gg4u/prova6.txt You can do that in one command like this: sed -n -e 's/\(<a[^h]*href="\)\([^"]*\)"\([^>]*>\)/\2/g; p' /Users/gg4u/prova4.txt \ | sed -e 's/<[^>]*>//g' > /Users/gg4u/prova6.txt That is two seds piped into each other. The first writes directly to the pipe and the second reads from the pipe, not from a file. | A question: | I have several several source files which I want to process in batch, and I | want to save only the final results (without saving intermediate file..) | so from list /Users/.../prova1,2,3,...,6.txt save the results as | /Users/.../provaa,b,c,d,...txt | | Which way could I use to automate ? A loop. Example: for file in file1 file2 file3 do sed -n -e 's/\(<a[^h]*href="\)\([^"]*\)"\([^>]*>\)/\2/g; p' "$file" \ | sed -e 's/<[^>]*>//g' >"$file-result.txt" done That reads from "file1" and writes to "file1-result.txt". And so on for file2 etc. | I could export list of file to do, but how to use it in batch from the | terminal? If the filenames were in a file, you could do this: while read file do sed -n -e 's/\(<a[^h]*href="\)\([^"]*\)"\([^>]*>\)/\2/g; p' "$file" \ | sed -e 's/<[^>]*>//g' >"$file-result.txt" done <your-exported-file-list where "your-exported-file-list" is the filename you exported to. At this point it is best to put all this in a small shell script, so you can edit and run it. Cheers, -- Cameron Simpson <[email protected]> DoD#743 http://www.cskk.ezoshosting.com/cs/ Carpe Daemon - Seize the Background Process - Paul Tomblin <[email protected]>