variables with dots and using double quoted sed?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting variables with dots and using double quoted sed?
# 1  
Old 03-01-2012
variables with dots and using double quoted sed?

Here is my script:

Code:
  1 #!/bin/bash
  2
  3 new() {
  4 list=$(find . -name '*.html' -or -name '*.htm' -or -name '*.php' -type f| xargs awk -F\" -v RS='<' '/^iframe src=/ {print $2}'|sed 's#http://##;s#/.*##' | sort -u)
  5
  6   if [ -z "$list" ]; then
  7         echo "No iframes found"
  8 exit
  9 else
 10 echo "I found the following frames:
 11 $list"
 12 echo -e "Paste the domain you want removed or type 'exit':>"
 13 read choice
 14 if [ $choice == exit ]; then
 15 echo "Exiting..."
 16 exit
 17 else
 18 find . -name "*php*" -or -name "*htm*" |xargs grep -rl "$choice" |xargs sed -e "s#[echo "]*<iframe src=[\\]*.http:\/\/${choice}[^>]*>[\w]*<\/iframe>[";]*##g"
 19 fi
 20 fi
 21 }
 22 ### Program start ###
 23 new

When I run it and enter a domain e.g. DOMAIN.COM it finds it in a file named index.php (for example). So I get the following error after I enter the domain and push ENTER:

Quote:
done.sh: line 18: iframe: No such file or directory
xargs: grep: terminated by signal 13
Obviously, the red "iframe" is of issue of some sort but I cannot really figure out what?
As to the xargs:grep error, I could try using just "choice" instead of "$choice" but then the variable would not be passed to sed?
Any suggestions? Thanks... ;]

Last edited by striker4o; 03-01-2012 at 08:29 PM..
# 2  
Old 03-02-2012
Escape the character < before iframe in the Sed statement. Maybe its trying to read thinking that <iframe is a file. To my knowledge giving "$choice" in quotes would not create any problem in grep command. Post sample few files from the files you grep so that members in this forum would give a alternate Sed solution.
# 3  
Old 03-02-2012
Thanks. The problem was actually indeed due to unescaped characters (stupid double quotation for the variable to work). However, it were the quotes that I needed to escape:

Not working:
Code:
find . -name "*php*" -or -name "*htm*" |xargs grep -rl "$choice" |xargs sed -e "s#[echo "]*<iframe src=[\\]*.http:\/\/${choice}[^>]*>[\w]*<\/iframe>[";]*##g"

Working:
Code:
find . -name "*php*" -or -name "*htm*" |xargs grep -rl "$choice" |xargs sed -e "s#[echo \"]*<iframe src=[\\]*.http:\/\/${choice}[^>]*>[\w]*<\/iframe>[\";]*##g"


Thanks for help!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace double quotes with a single quote within a double quoted string

Hi Froum. I have tried in vain to find a solution for this problem - I'm trying to replace any double quotes within a quoted string with a single quote, leaving everything else as is. I have the following data: Before: ... (32 Replies)
Discussion started by: pchang
32 Replies

2. Shell Programming and Scripting

Awk-sed - wc : how to count DOTS "."'s in a file.

Hi Experts , file: EST 2013::.................................................................................................................................................................................................................................................cmihx021:/home/data1/ ... (11 Replies)
Discussion started by: rveri
11 Replies

3. Shell Programming and Scripting

Deleting double quoted string from a line when line number is variable

I need to remove double quoted strings from specific lines in a file. The specific line numbers are a variable. For example, line 5 of the file contains A B C "string" I want to remove "string". The following sed command works: sed '5 s/\"*\"//' $file If there are multiple... (2 Replies)
Discussion started by: rennatsb
2 Replies

4. Shell Programming and Scripting

underscore to dots

Hi, I have been trying to change underscores to dots. For example: 1122_91 1022_233 . 2237_23 9382_2339 2998_234 345_257 . . Desired output: 1122.91 1022.233 . 2237.23 9382.2339 2998.234 345.257 . . Any idea? Thanks (4 Replies)
Discussion started by: iconig
4 Replies

5. Shell Programming and Scripting

Take quoted output from one script as quoted input for another script

Hi, I have a script output.sh which produces the following output (as an example): "abc def" "ghi jkl" This output should be handled from script input.sh as input and the quotes should be treated as variable delimiters but not as regular characters. input.sh (processing positional... (2 Replies)
Discussion started by: stresing
2 Replies

6. Shell Programming and Scripting

Convert CSV file (with double quoted strings) to pipe delimited file

Hi, could some help me convert CSV file (with double quoted strings) to pipe delimited file: here you go with the same data: 1,Friends,"$3.99 per 1,000 listings",8158here " 1,000 listings " should be a single field. Thanks, Ram (8 Replies)
Discussion started by: Ram.Math
8 Replies

7. Shell Programming and Scripting

Replace double double quotes using AWK/SED

Hi, I have data as "01/22/97-"aaaaaaaaaaaaaaaaa""aaa""aabbbbbbbbcccccc""zbcd""dddddddddeeeeeeeeefffffff" I want to remove only the Consequitive double quotes and not the one which occurs single. My O/P must be ... (2 Replies)
Discussion started by: Bhuvaneswari
2 Replies

8. Shell Programming and Scripting

Use variables with double quotes sed -i

I have the following line of code: sed -i "/MatchText/ s/${tgrepLine}/${tNewLine}/" filename.outputfilename.output contains this: blablabla PATH=".:/home/root/bin/:/usr/local/bin/" blablablaVariable ${tgrepLine} contains: PATH=".:/home/root/bin/:/usr/local/bin/" Variable ${tNewLine}... (3 Replies)
Discussion started by: inspire87
3 Replies

9. Shell Programming and Scripting

Double Substitution variables in ksh

Hi I have a variable whose value is like this i=/test/test1/test2/myfile.cd.070505123457 i would like to have the value of myfile.cd stored into another variable my attempt is test=${i##*/} ;echo $test ##and i get myfile.cd.070505123457 since what i wnat is myfile.cd i try this... (19 Replies)
Discussion started by: xiamin
19 Replies

10. AIX

how to pass variables surrounded in double quotes to awk?

Hi, I'm making progress on this but hung up on one last detail. I'd like to use AWK to pass the system date and time(among other things) to the first line of a file. Here's what I have: BEGIN {TOTALPP = 0;FREEPP=0;USEDPP=0;print "LPAR NAME:",lpar,"DATE:",tdate } I call AWK with the... (4 Replies)
Discussion started by: cruiser
4 Replies
Login or Register to Ask a Question