I want to display something if the page url is ending with a +
I tried this :
<?php if(substr($_SERVER['REQUEST_URI'],-1) == '+') echo 'lalala'; ?>
But it's not working :(
Thanks for your help
Related
Need to remove some part of the url and keep the remaining part same .
Below is the part of my text file which contains like this
{
host = "http://nxt-newepisode.xcfm.crata.dive.com/err1.2.2/table/kenny.xml.gz"
}
{
host = "http://nxt-secondepisode.xcfm.crata.dive.com/err1.2.2/table/kenny.xml.gz"
}
from above two urls i want get rid off nxt- and keep the rest . I know using
sed -i 's/nxt-//g' FILE
can solve the issue but i want to be specific and only remove nxt- for first url and nxt- from second url without making changes to rest of file.
I am trying this
sed -i '/host/s#"http://nxt-newepisode.*"#" "#' FILE
Could you please try following.
awk '/host/ && ++count==1{sub(/nxt-/,"")} 1' Input_file
Once you are happy with results then to save output into Input_file use following:
awk '/host/ && ++count==1{sub(/nxt-/,"")} 1' Input_file > temp && mv temp Input_file
I am very new to scripts, but I am writing a little rsync script for my NAS. I am now trying to edit the output of the rsync "stats" parameter.
Because this parameter give a lot of details, and I only need the final results, I start by only keeping the part I want :
sed -e '/Number/,$!d' $log > tmp && mv tmp $log
So that output for now looks like this :
enter image description here
So then I would like to remove the kind of timestamp from each line :
sed -e 's,.*] ,,' $log > tmp && mv tmp $log
So now it looks like this (in Outlook, as I send this result by email) :
enter image description here
So then, I thought I could add a new line. I have tried multiples possibilities, but it doesn't work the way I would like. I can't show you a 3rd picture though.
Would you have any suggestion for me :) ? Thanks for your help !
Thanks Lars for your answer. Your code did what I wanted, but the problem persisted.
Lucky me, I found my problem with outlook : https://naveensnayak.wordpress.com/2012/08/30/ms-outlook-messing-up-line-breaks/
So instead of adding a new line, I made a very little change to my code :
sed -e 's,.*], ,' $log > tmp && mv tmp $log
Because there is a whitespace after my bracket (]), and that I add a 2nd whitespace, now my file looks nice in Outlook.
You can add a newline to a file with the echo command:
> cat test.txt
1
2
3 > echo -e "\n" >> test.txt
> cat test.txt
1
2
3
>
-e enables the backslash interpretation
"\n" is interpreted as newline
>> appends instead of overwrites
I am needing to parse an HTML file and remove everything except for the anchor tags in their entirety. So for example:
<html>
<body>
<p>boom</p>
Example
</body>
</html>
I only need to keep:
Example
I am using cURL to retrieve the html and a small snippet of code I found that strips everything but the anchor text of the tag. This is what I am using:
curl http://www.google.com 2>&1 | perl -pe 's/\<.*?\>//g'
Is there a simple command line way to do this? My end goal is to put this into a bash script and execute it. I am having a very difficult time understanding regular expressions and perl.
Using Mojolicious command line tool mojo:
mojo get http://www.google.com 'a'
Outputs:
<a class="gb1" href="http://www.google.com/imghp?hl=en&tab=wi">Images</a>
<a class="gb1" href="http://maps.google.com/maps?hl=en&tab=wl">Maps</a>
<a class="gb1" href="https://play.google.com/?hl=en&tab=w8">Play</a>
<a class="gb1" href="http://www.youtube.com/?tab=w1">YouTube</a>
<a class="gb1" href="http://news.google.com/nwshp?hl=en&tab=wn">News</a>
<a class="gb1" href="https://mail.google.com/mail/?tab=wm">Gmail</a>
<a class="gb1" href="https://drive.google.com/?tab=wo">Drive</a>
<a class="gb1" href="http://www.google.com/intl/en/options/" style="text-decoration:none"><u>More</u> »</a>
<a class="gb4" href="http://www.google.com/history/optout?hl=en">Web History</a>
<a class="gb4" href="/preferences?hl=en">Settings</a>
<a class="gb4" href="https://accounts.google.com/ServiceLogin?hl=en&continue=http://www.google.com/" id="gb_70" target="_top">Sign in</a>
Install Google Chrome
Advanced search
Language tools
Chromebook: For students
Advertising Programs
Business Solutions
+Google
About Google
Privacy & Terms
For a helpful 8 minute introductory video, check out: Mojocast Episode 5
Using Mojolicious, as #Miller above, but more exactly select the <a ... rel= :
If you have an html file
perl -Mojo -E 'say $_ for x(b("my.html")->slurp)->find("a[rel]")->each'
or for the online resource
perl -Mojo -E 'say $_ for g("http://example.com")->dom->find("a[rel]")->each'
#or
perl -Mojo -E 'g("http://example.com")->dom->find("a[rel]")->each(sub{say $_})'
If you want more granular control over your HTML, then you can use HTML::TagParser module available on CPAN.
use strict;
use warnings;
use HTML::TagParser;
my $html = HTML::TagParser->new( '<html>
<body>
<p>boom</p>
Example
</body>
</html>' );
my #list = $html->getElementsByTagName( "a" );
for my $elem ( #list ) {
my $name = $elem->tagName;
my $attr = $elem->attributes;
my $text = $elem->innerText;
print "<$name";
for my $key ( sort keys %$attr ) {
print " $key=\"$attr->{$key}\"";
}
print $text eq "" ? " />" : ">$text</$name>" , "\n";
}
Output:
Example
Ingy döt Net's pQuery deserves a mention:
perl -MpQuery -E 'pQuery("http://www.ubu.com/sound/barthes.html")
->find("a")->each(sub{say pQuery($_)->toHtml})'
Just the links:
perl -MpQuery -E 'pQuery("http://www.ubu.com/sound/barthes.html")
->find("a")->each(sub{say $_->{href}})'
Although - unlike mojo - there's no command line tool (i.e. not yet - it's not that kind of tool per se and is still "under construction"), it's a module to have on your watch list.
Can some one help me to find a regular expression for the pattern below,
I am trying to use regular expression to match a patter in shell script.
The pattern could be a combination of 'ab' 'xy' 'ij' 'pqr', in any order and seperated by a comma ',' or only 'all'
Ex.
1) "ab,xy,ij,pqr" - valid
2) "ij,pqr" - valid
3) "all" - valid
4) "ij,ab," - invalid because it ends with a comma
5) "all,xy" - invalid because 'all' cannot be combined with xy ij pqr or ab
6) ",xy" - invalid because it starts with comma
7) "xy" - valid
Thank you.
#konsolebox #491243 #ajp15243 #Jerry
Looks like I am doing something wrong, it works only for the RE regex4="(ab|xy|ij|pqr)(,(ab|xy|ij|pqr))*" so far and that too only if the string is like "ab,xy" just "ab" doesn't work.
Here is what I have attempted so far:
#!/usr/bin/ksh
echo
echo echo $1
echo
regex2="^(all|(ab|xy|ij|pqr)(,(ab|xy|ij|pqr))*)$"
regex3="^(all|(ab|xy|ij|pqr)(,(ab|xy|ij|pqr))*)$"
regex4="(ab|xy|ij|pqr)(,(ab|xy|ij|pqr))*"
if [[ $1 == $regex2 ]]
then
echo "You got it again 22222222 !"
fi
if [[ $1 == $regex3 ]]
then
echo "You got it again 33333333 !"
fi
if [[ $1 == $regex4 ]]
then
echo "You got it again 44444444 !"
fi
Output:
$
$ test.ksh ab,xy
echo ab,xy
You got it again 44444444 !
$
$
$
$ test.ksh ab
echo ab
$
1:30 PST
Ok, had some improvement:
"((ab|xy|ij|pqr)|(ab|xy|ij|pqr)(,(ab|xy|ij|pqr))*)|all)$"
this one works when the input is "xy", "xy,ab" but it also treating "xy,ab,all" as valid input.
I think this will do it.
^(((ab|xy|ij|pqr)(,(ab|xy|ij|pqr))*)|all)$
Screenshot
Probably this:
^(all|(ab|xy|ij|pqr)(,(ab|xy|ij|pqr))*)$
ok, looks like finially the below RE worked, thank you all for the help.
(all)|(ab|xy|ij|pqr)|(ab|xy|ij|pqr)(,(ab|xy|ij|pqr)*)
I have a project that includes 49 folders, each one has a file called index.php
All index.php files are almost the same except for one part that changes depending on the folder it is in.
<?php include_once("/home/bgarch/public_html/galleryheader.html"); ?>
<?php include_once("/home/bgarch/public_html/culture/loadscripts.html"); ?>
</head>
<body>
<div class="header">
<?php include_once("/home/bgarch/public_html/header.html"); ?>
</div>
<div class="clear"></div>
<div class="displaywrapper">
<?php include_once("content.html"); ?>
</div></div>
<div class="clear"></div>
<?php include_once("/home/bgarch/public_html/footer.html"); ?>
In the second line where the above reads: "../culture/.." the word culture is the variable and is different based on the folder it is in.
What I need to do know is do a "Find/Replace all in project" that automatically replaces all the text inside each 'index.php' file with the following"
<?php include_once("http://www.bgarchitect.co.nz/subPage/index.php"); ?>
I have spent the past 2 hours trying to figure out regular expressions to acomplish this but have been unsuccessful so far.
Maybe it is not possible to do so?
Anyway, I thought I'd ask a question here in hopes it is in fact much easier than I anticipated. So any help/pointer/hints or tricks are much appreciated.
Thanks for reading,
Jannis
If I understood right, you want to replace the word culture (which is the current directory) with the word subPage?
You can do this with the help of TextMate bundles.
Bundles > Bundle editor > Edit commands, than add a New command.
Add this as a command. I think it does what you want. You have to set the input to the command as Entire document and the output to Replace document.
#!/bin/bash
sed "s/"${TM_DIRECTORY##*/}"/theWordYouWanToReplaceTheDirWith/g" | cat