My god Bakunin, you're a master in sed! Thank you so much for taking the time to write these lines!
OK then, let me try on your sed to see if I understood:
I'll stay with my understanding of the first part of the command. You're actually not passing any command yet to sed. So what you're looking for in:
is the line that matches "href [any kind of character in between]view more" or to put it another way: you get that line: Now comes the good part: Within that line, substitute: "[any kind of character before] href=" [following string omitting the possible " characters within the string] by [this same string without " characters that you just found] and print.
but how come the "> view more </a>" portion of the line was left out of the sed? because from what I understand you're including .* which still should include all the characters at the end of the line, shouldn't it?
Thanks as usual!
Best!
EDIT-----
I just tried:
and it gave me:
So I guess that what's happening with your code is that when you tell sed to exclude the " it simply stops at it and do not go on with the rest of the line.
---------- Post updated at 06:08 PM ---------- Previous update was at 04:43 PM ----------
Quote:
Originally Posted by MadeInGermany
Exactly. The first character that matches in the trailing .* is a quote.
As I said, the leading and trailing .* are needed to "match away" the entire line. Otherwise only the matching portion would be substituted.
---------- Post updated at 12:15 ---------- Previous update was at 11:44 ----------
Now to your second requirement. Can give a headache even for experienced guys.
In your example the ' is a problem for the shell, in which you call
There is no problem if you save the sed code in a separate file and run it with
And the contents of the sed-script
You can add another match in a second line
but it won't match if the first match was successful and the input line was substituted.
It is necessary to save and restore the line.
Another aspect is greediness. The * wants to match as much it can. A leftmost * is most greedy.
That means /.*'branch'/ matches the rightmost 'branch'.
--
Last but not least, the shell method to print a ' within a ' ' string goes like this
Actually it is a concatenation of 'left' and 'right' with a \' in between.
For an embedded sed script it is enough to remember to exchange each literal ' by '\''.
Hey MadeinGermany!
Bakunin's explaination helped me a lot go through your answer but I still got a few questions:
Quote:
In your example the ' is a problem for the shell, in which you call
There is no problem if you save the sed code in a separate file and run it with
Why is it a problem for the shell?
When I paste the previous "PHP" (I assume it's PHP) code into a txt (examplesed.txt) for testing the command:
it yields nothing. There's no output whatsoever...
Quote:
Code:
/itemprop='brand'/ s/.*'brand'>\([^<]*\).*/\1/p
You can add another match in a second line
Code:
/itemprop='name'/ s/.*'name'>\([^<]*\).*/\1/p
but it won't match if the first match was successful and the input line was substituted.
It is necessary to save and restore the line.
Code:
h /itemprop='brand'/ s/.*'brand'>\([^<]*\).*/\1/p g /itemprop='name'/ s/.*'name'>\([^<]*\).*/\1/p
On that one, I'm not sure to follow either... My objective is to integrate these commands within a loop. So I will have the first iteration and it'll write the output to a file, then the second command (with 'name' for instance) > echo to a file and go to the third iteration etc...
Wouldn't that work under that setting?
Quote:
Another aspect is greediness. The * wants to match as much it can. A leftmost * is most greedy.
That means /.*'branch'/ matches the rightmost 'branch'.
I guess that in my case, my problem child would be 'name' that has a first appearance at the beginning of the line.
But in that case couldn't I use 2 right before the 'p' (print command).
I learnt on the web that putting a 1 or a 2 before the p would yield the first or second appearance of the term I'm looking for... wouldn't that work?
All the best!
Last edited by Ardzii; 01-30-2017 at 11:54 AM..
Reason: More discoveries!!
Hi all,
Still a newbie and learning as I go ... as you do :)
Have created this script to report on disc usage and I've just included the ChkSpace function this morning.
It's the first time I've read a file (line-by-bloody-line) and would like to know if I can improve this script ?
FYI - I... (11 Replies)
Hi ,
i'm searching for files over many Aix servers with rsh command using this request :
find /dir1 -name '*.' -exec ls {} \;
and then count them with "wc"
but i would improve this search because it's too long and replace directly find with ls command but "ls *. " doesn't work.
and... (3 Replies)
Wrote this script to find the date x days before or after today. Is there any way that this script can be speeded up or otherwise improved?
#!/usr/bin/sh
check_done() {
if
then
daysofmth=31
elif
then
if
... (11 Replies)
hi someone tell me which ways i can improve disk I/O and system process performance.kindly refer some commands so i can do it on my test machine.thanks, Mazhar (2 Replies)
I have a data file of 2 gig
I need to do all these, but its taking hours, any where i can improve performance, thanks a lot
#!/usr/bin/ksh
echo TIMESTAMP="$(date +'_%y-%m-%d.%H-%M-%S')"
function showHelp {
cat << EOF >&2
syntax extreme.sh FILENAME
Specify filename to parse
EOF... (3 Replies)
I have a 10Gbps network link connecting two machines A and B. I want to transfer 20GB data from A to B using TCP. With default setting, I can use 50% bandwidth. How to improve the throughput? Is there any way to make throughput as close to 10Gbps as possible? thanks~ :) (3 Replies)
Hi All,
I have written a script as follows which is taking lot of time in executing/searching only 3500 records taken as input from one file in log file of 12 GB Approximately.
Working of script is read the csv file as an input having 2 arguments which are transaction_id,mobile_number and search... (6 Replies)
I just wrote a very small script that improves readability on system sulog. The problem with all sulog is there is lack of clarity whether the info you are looking at is the most current. So if you just need a simple soution instead of going thru the trouble of writing a script that rotate logs and... (0 Replies)
Gents.
I have 2 different scripts for the same purpose:
raw2csv_1
Script raw2csv_1 finish the process in less that 1 minute
raw2csv_2
Script raw2csv_2 finish the process in more that 6 minutes.
Can you please check if there is any option to improve the raw2csv_2. To finish the job... (4 Replies)
Gents,
Is there the possibility to improve this script to be able to have same output information.
I did this script, but I believe there is a very short code to get same output
here my script
awk -F, '{if($10>0 && $10<=15) print $6}' tmp1 | sort -k1n | awk '{a++} END { for (n in a )... (23 Replies)