I wanted the script to use variables to hold those starting url and end url and use that varibles in "sed" but it does not work.
my script now looks like this:
#!/bin/bash
a="https://www.example.com/files/AE2350.txt"
b="https://www.example.com/files/AE2440.txt"
cat temp.txt | sed '/$a/,/$b/!d' > temp1.txt
Thanks for the solution but unfortunately the output are showing different. when I run the above said sed the result which I get are as follows:
https://www.example.com/files/AE2350.txt (it is $a)
https://www.example.com/files/AE2351.txt (this line does not present in source file but added after running sed)
https://www.example.com/files/AE2352.txt (this line does not present in source file but added after running sed)
...
https://www.example.com/files/AE2369.txt (this URL present in source file)
https://www.example.com/files/AE2370.txt (this line does not present in source file but added after running sed)
https://www.example.com/files/AE2371.txt (this line does not present in source file but added after running sed)
...
https://www.example.com/files/AE2387.txt (this URL present in source file)
https://www.example.com/files/AE2388.txt(it is $b)
the above result shows that, sed is adding additional sequence of files between $a and $b.
I just want the sed to copy exact same url which is present between $a and $a. Like
https://www.example.com/files/AE2350.txt (this is $a)
https://www.example.com/files/AE2369.txt
https://www.example.com/files/AE2387.txt
https://www.example.com/files/AE2388.txt
https://www.example.com/files/AE2392.txt
https://www.example.com/files/AE2440.txt(this is $b)
The sed does not have variables, so you fight with escaping of the RE special characters.
Not so with shell builtins. Create a speaking function, and the main program is quite simple:
#!/bin/bash
function sift_out(){
local begin=$1 end=$2
local line prt=0
while read line
do
case $line in (*"$begin"*) prt=1;; esac
[ $prt -eq 1 ] && printf "%s\n" "$line"
case $line in (*"$end"*) prt=0;; esac
done
}
a="https://protect2.fireeye.com/v1/url?k=4ae50b7e-1445ebe0-4ae54be5-86ee86bd5107-93ba947c1d9f7dbf&q=1&e=cc7ff68e-e191-4790-a487-47afb74e7fab&u=https%3A%2F%2Fwww.exampl.com%2Ffiles%2FAE2350.txt"
b="https://protect2.fireeye.com/v1/url?k=98cce59c-c66c0502-98cca507-86ee86bd5107-b23623b84f1ae9bf&q=1&e=cc7ff68e-e191-4790-a487-47afb74e7fab&u=https%3A%2F%2Fwww.exampl.com%2Ffiles%2FAE2440.txt"
sift_out "$a" "$b" <temp.txt
will the above sed work for the url like https://secure.example.co.in/srv-01/2009/files/111/AE2392.txt? sorry for asking this because I just wanted this script to be work in any kind of URLs.
and another question is why \ is not been used around "files" like \%https://www\.example\.com/\files/\AE'"$a"'\.txt%
what I mean to say is.. if I change the web URL from sed '\%https://www\.example\.com/files/AE'"$a"'\.txt% to sed '\%https://secure\.example\.co\.in/srv-01/2009/files/111/AE'"$a"'\.txt%
will it still work? or do I have to change the sed pattern?
my another question was, in sed you have sed '\%https://www\.example\.com/files/AE'"$a"'\.txt%, ..., so why \ is not used with around "files" like sed '\%https://www\.example\.com\/files\/AE'"$a"'\.txt%,....
maybe my question is wrong but I am just curious to know.