extract text between two words on a single line


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers extract text between two words on a single line
# 8  
Old 04-13-2011
thx for the reply. but this is not working. I had tried this earlier and it doesn't give any output at all maybe due the volume of records ? not sure....when I size down the file to only two to three records the same sed command works.
# 9  
Old 04-15-2011
anyone got an idea on the above ?
# 10  
Old 04-15-2011
Try the following:
1) Copy the file to a temp file.
2) Keep dividing it in half until you can run the "sed" command successfuly.
3) From this successful file, keep adding X amount of records until it does not work.

Let us know the results:
a) What is the file size (bytes) where the command breaks.
b) How many lines it has.

Are you giving sufficient time for the "sed" command to work?

Does it give any error message at all?
# 11  
Old 04-15-2011
The problem is that your file is made of 1 very long line (at least, that is the file i have downloaded)
maybe give a try to

Code:
awk 'gsub("<[/]*FEEDMessage>","\n&\n",$0)' File.xml | sed -n '/<FEEDMessage>/,/<\/FEEDMessage>/p'

Use nawk instead of awk if you are on SunOS / Solaris

If you want it then collapsed into one long line you can still pipe it into something like

Code:
| paste s -d "\0" -

so something like

Code:
awk 'gsub("<[/]*FEEDMessage>","\n&\n",$0)' File.xml | sed -n '/<FEEDMessage>/,/<\/FEEDMessage>/p' | paste -s -d "\0" - >new.xml


Last edited by ctsgnb; 04-15-2011 at 01:40 PM..
# 12  
Old 04-18-2011
thanks ctsgnb! from this I got a clue and wrote below command which worked for me Smilie

nawk -F"<" ' { for(i=18;i<=NF-1;i++){ print "<"$i } }' File.xml > temp.xml
tr -d '\n' < temp.xml > File.xml
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell - Read a text file with two words and extract data

hi I made this simple script to extract data and pretty much is a list and would like to extract data of two words separated by commas and I would like to make a new text file that would list these extracted data into a list and each in a new line. Example that worked for me with text file... (5 Replies)
Discussion started by: dandaryll
5 Replies

2. Shell Programming and Scripting

I need to extract uique words from text file

Hello programmers, I need to create a list of unique words from a text file using PERL...may i have the code for that please? Thank you (1 Reply)
Discussion started by: alsohari
1 Replies

3. Shell Programming and Scripting

Command line: add text wrapper around words

I am trying to build a sinkhole for BIND. I created a master zone file for malicious domains and created a separate conf file, but I am stuck. I have a list of known bd domains that is updated nightly. The file simply contains the list of domains, one on each line: Bad.com Bad2.com... (4 Replies)
Discussion started by: uuallan
4 Replies

4. UNIX for Dummies Questions & Answers

Append a line to single column text file

I would like to add a line to the end of a single column text file. How do I go about doing that? Input: BEGIN 1 2 3 Output: BEGIN 1 2 3 END Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

5. Shell Programming and Scripting

get the fifth line of a text file into a shell script and trim the line to extract a WORD

FOLKS , i have a text file that is generated automatically of an another korn shell script, i want to bring in the fifth line of the text file in to my korn shell script and look for a particular word in the line . Can you all share some thoughts on this one. thanks... Venu (3 Replies)
Discussion started by: venu
3 Replies

6. Shell Programming and Scripting

Extract X words from end of line, minus last keynumber X

The file contains one line of text followed by a number. I want to take the number X at the end, take it out and display the last X words. X is the key telling me how many words from the end that I want and X will always be less than the number of words, so no problem there. Example input and... (4 Replies)
Discussion started by: fubaya
4 Replies

7. Shell Programming and Scripting

Help substituting text in a file having a single line but no newline char

Hello, Need help substituting a particular word in a file having a single line but no newline character at the end. I was trying to use sed but it doesn't work probably because there is no newline char at the end of the line. $ cat hlq_detail /outputs/alvan23/PDFs/bills $ cat... (5 Replies)
Discussion started by: Shan_u2005
5 Replies

8. Shell Programming and Scripting

deleting blank line and row containing certain words in single sed command

Hi Is it possible to do the following in a single command /usr/xpg4/bin/sed -e '/rows selected/d' /aemu/CALLAUTO/callauto.txt > /aemu/CALLAUTO/callautonew.txt /usr/xpg4/bin/sed -e '/^$/d' /aemu/CALLAUTO/callautonew.txt > /aemu/CALLAUTO/callauto_new.txt exit (1 Reply)
Discussion started by: aemunathan
1 Replies

9. Shell Programming and Scripting

grep multiple words in a single line

Hi.. How to search for multiple words in a single line using grep?. Eg: Jack and Jill went up the hill Jack and Jill were best friends Humpty and Dumpty were good friends too ---------- I want to extract the 2nd statement(assuming there are several statements with... (11 Replies)
Discussion started by: anduzzi
11 Replies

10. Shell Programming and Scripting

Script to add a single line to middle of text file.

I've got a configuration file that is filled with xml text statements for example: <...../> <...../> <...../> <data id="java-options" value="-server -Djava.security.policy..../> <...../> <...../> <...../> I want to write a korn shell script that will go to this specific line and add a... (2 Replies)
Discussion started by: progkcp
2 Replies
Login or Register to Ask a Question