Sponsored Content
Top Forums Shell Programming and Scripting Replacing text in between the string Post 302829783 by 2by4 on Saturday 6th of July 2013 01:15:45 AM
Old 07-06-2013
Code:
$ which sed; uname -a
/bin/sed
Linux ubuntu 3.5.0-34-generic #55~precise1-Ubuntu SMP Fri Jun 7 16:25:50 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

sed --version
GNU sed version 4.2.1

---------- Post updated at 10:05 PM ---------- Previous update was at 10:02 PM ----------

Don, if I read correct your script assumes < is at the beginning of the line:

Code:
sed '/^<

which works on the sample text, however in my case, I have a ton of text before and after image tags.

---------- Post updated at 10:08 PM ---------- Previous update was at 10:05 PM ----------

Looking through the output file looks good Smilie

how can I print ONLY text, not an entire line between <IMG and the > ?

Code:
sed -nE '/IMG/,/jpg">/p' output

prints an entire line, I'd like to see any variations and print ONLY between <IMG and the >

---------- Post updated at 10:10 PM ---------- Previous update was at 10:08 PM ----------

Code:
sed -nE '/<[Ii][Mm][Gg]\ src/,/jpg">/p' output

does the same thing print entire line Smilie

---------- Post updated at 10:15 PM ---------- Previous update was at 10:10 PM ----------

Code:
grep -o "\<[Ii][Mm][Gg].*.jpg\"" output

does match, however it will print all in one line if there are multiple <IMG tags in one line, plus it always includes lots of junk.

Code:
IMG src="https://www.unix.com/images/2359_4703925.jpg"><BR><IMG src="https://www.unix.com/images/2359_7990660.jpg"
IMG style="WIDTH: 448px; HEIGHT: 339px" height=437 src="https://www.unix.com/images/2360_4703925.jpg" width=512></SPAN></P><P><SPAN style="FONT-SIZE: 8pt"><IMG style="WIDTH: 434px; HEIGHT: 369px" height=433 src="https://www.unix.com/images/2360_7990660.jpg" width=438></SPAN></P><SPAN style="FONT-SIZE: 8pt; mso-bidi-font-size: 12.0pt"><o:p><IMG style="WIDTH: 559px; HEIGHT: 385px" height=364 src="https://www.unix.com/images/2360_8832613.jpg"


Last edited by Scrutinizer; 07-06-2013 at 04:36 AM.. Reason: Add many more code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replacing text

I was using the following code to replace the path names and it works when it is echo "$PWD/$f" | sed -e 's/^.*chris\.domain\.com/chris.domain.com/' IN fact it works great However I tried to incorporate a variable echo "$PWD/$f" | sed -e... (3 Replies)
Discussion started by: chrchcol
3 Replies

2. Shell Programming and Scripting

string replacing

hii, i need a unix command which replaces all occurrences of a substring within a string with another substring. My solution: string="plalstalplal" sub1="al" sub2="mlkl" echo sed 's/$s2/$s3/g' < s1 > p i want to know how to read the variables s2 and s3.. thaks a lot bye (1 Reply)
Discussion started by: priya_9patil
1 Replies

3. Shell Programming and Scripting

Replacing Text in Text file

Hi Guys, I am needing some help writing a shell script to replace the following in a text file /opt/was/apps/was61 with some other path eg /usr/blan/blah/blah. I know that i can do it using sed or perl but just having difficulty writing the escape characters for it All Help... (3 Replies)
Discussion started by: cgilchrist
3 Replies

4. UNIX for Dummies Questions & Answers

Replacing string

Hi there, I'd like to replace STRING_ZERO in FILE_ZERO.txt with the value of VALUEi-th by using something like that: VALUE1=1000 VALUE2=2000 VALUE3=3000 for((i=1;i<=3;i++)); do sed "s/STRING_ZERO/$VALUE'$i'/" FILE_ZERO.txt >> FILE_NEW.txt; done but it doesn't work... Any help... (9 Replies)
Discussion started by: Giordano Bruno
9 Replies

5. Shell Programming and Scripting

replacing a string in multiple subdirs to a new string??

I have following set of dirs: /dir1/dir2/subdir1 file1 file2 /dir1/dir3/subdir1 file4 file5 /dir1/dir4/subdir1 file6 file7 All of these files have a common string in them say "STRING1", How can I... (3 Replies)
Discussion started by: Hangman2
3 Replies

6. Shell Programming and Scripting

Help replacing string

Help! I'm trying this command but keep getting illegal syntax etc. awk '{ sub(/00012345/,"000123456"); print}' >newfile I don't understand. It works on one unix machine but not another! (4 Replies)
Discussion started by: Grueben
4 Replies

7. UNIX for Dummies Questions & Answers

replacing a string with another string in a txt file

Dear all, I have a file like below. I want to replace all the '.' in the 3rd column with 'NA'. I don't know how to do that. Anyone has an iead? Thanks a lot! 8 70003200 21.6206 9 70005700 17.5064 10 70002200 . 11 70005100 19.1001 17 70008000 16.1970 32 70012400 26.3465 33... (9 Replies)
Discussion started by: forevertl
9 Replies

8. Shell Programming and Scripting

Help with replacing string

Hi All, I have below requirement: I need to read each line in file.txt and replace string starting from position 9 to 24 {111111111111111,222222222222222,333333333333333} by common string "444444444444444" and save file. File.txt: 03000003111111111111111 ... (3 Replies)
Discussion started by: smalode
3 Replies

9. Programming

Need help for replacing a string in a text file at runtime !

Hi All, I am facing an issue... I need to replace some string in a text file while the same file is read by some other user at the same time. The other user is using it in the Read only mode. So I can't create a temporary file and write the content first and then write it back into the original... (2 Replies)
Discussion started by: agupta2
2 Replies

10. Shell Programming and Scripting

Replacing a string

Hi All, I have a many folders in a directory under which there are many subdirectories containing text files containing the word "shyam" in them.I want all the files in all the directories containing "shyam to "ram" ?? sed "s/shyam/ram/g" does it ??But anyone can help me with the script ?? ... (3 Replies)
Discussion started by: Pradeep_1990
3 Replies
All times are GMT -4. The time now is 12:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy