The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Moving a part of the text in a file srikanthgoodboy Shell Programming and Scripting 6 05-04-2009 11:58 AM
awk, perl Script for processing a single line text file hmsadiq Shell Programming and Scripting 1 04-12-2009 04:44 PM
Need help to modify perl script: Text file with line and more than 1 space srsahu75 Shell Programming and Scripting 3 03-20-2009 05:28 PM
Shell script to search for text in a file and copy file imeadows UNIX for Dummies Questions & Answers 9 11-12-2008 09:12 PM
Perl script to load text file into DB field aristegui Shell Programming and Scripting 2 09-15-2008 04:55 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 3 Weeks Ago
asandy1234 asandy1234 is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 14
I changed it but I'm getting a syntax error

Document.bash[18]: 0403-057 Syntax error at line 20 : `(' is not expected.
  #2 (permalink)  
Old 3 Weeks Ago
frans's Avatar
frans frans is offline
Registered User
  
 

Join Date: Oct 2009
Location: Drôme, France
Posts: 100
What would be nice is if i could get a sample of the file you want to parse.
I've modified the code
Code:
LINE="lbla bla bla jcjfd<text>what i want</text>flh%(j blablabla<text>second occurence</text>juhgfiuhf<text>third occ</text>jkhgq"
I=1
LINE=${LINE#*<text>}	# Removes all from the begining up to the first "<text>"
LINE=${LINE%</text>*}	# Removes all from the end down to the last "</text>"
while echo $LINE | grep -q "<text>"	# more than one field
do	TEXT[$I]=${LINE%%</text>*}
	LINE=${LINE#*<text>}
	let I=I+1
done
TEXT[$I]=${LINE%</text>*}	# for the last one
{	# To see what we've done
	N=$I
	I=1
	while [ $I -le $N ]
	do
		echo "TEXT[$I] = ${TEXT[$I]}"
		let I=I+1
	done
}
  #3 (permalink)  
Old 3 Weeks Ago
asandy1234 asandy1234 is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 14
Thanks Frans this code is working, just changed <text> to "<text>" .
Can you let me know how to modify this code to accomodate input and output file.

Thanks.

Last edited by asandy1234; 3 Weeks Ago at 01:16 PM..
  #4 (permalink)  
Old 3 Weeks Ago
frans's Avatar
frans frans is offline
Registered User
  
 

Join Date: Oct 2009
Location: Drôme, France
Posts: 100
Revisited

Revisited and uncommented script for in from file and out to file
Code:
I=1
while read LINE
do
	LINE=${LINE#*<text>}
	LINE=${LINE%</text>*}
	while echo $LINE | grep -q "<text>"
	do
		echo "$I ${LINE%%</text>*}"
		LINE=${LINE#*<text>}
		let I=I+1
	done
	echo "$I ${LINE%</text>*}"
        let I=I+1
done < inputfile > ouputfile
The output gives numbered lines with the text. If you don't want the numbers, remove the $I in the echo
If this doesn't work, send me a big sample of xml to process
  #5 (permalink)  
Old 3 Weeks Ago
asandy1234 asandy1234 is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 14
Wow great Frans, the code works. Thank you very much for ur help.

---------- Post updated at 02:14 PM ---------- Previous update was at 01:33 PM ----------

Hi Frans, one more issue.
The code works fine if the file is one line but if the xml is multi line the code doesn't work.
Please find below the xml
=====================================================

Last edited by asandy1234; 3 Weeks Ago at 07:09 PM..
  #6 (permalink)  
Old 3 Weeks Ago
frans's Avatar
frans frans is offline
Registered User
  
 

Join Date: Oct 2009
Location: Drôme, France
Posts: 100
A version with numbering
Code:
LINE=`cat inputfile`
I=1
{
    LINE=${LINE#*<text>}    # Removes all from the begining up to the first "<text>"
    LINE=${LINE%</text>*}    # Removes all from the end down to the last "</text>"
    while echo $LINE | grep -q "<text>"    # more than one field
    do
    echo "$I ${LINE%%</text>*}"
        LINE=${LINE#*<text>}
        let I=I+1
    done
    echo "$I ${LINE%</text>*}"    # for the last one
} > ouputfile
Or without (simplier)
Code:
LINE=`cat inputfile`
{
    LINE=${LINE#*<text>}    # Removes all from the begining up to the first "<text>"
    LINE=${LINE%</text>*}    # Removes all from the end down to the last "</text>"
    while echo $LINE | grep -q "<text>"    # more than one field
    do
    echo "${LINE%%</text>*}"
        LINE=${LINE#*<text>}
    done
    echo "${LINE%</text>*}"    # for the last one
} > ouputfile
Take in the first line around input file that are backticks [AltGr-7] and not single quotes !
  #7 (permalink)  
Old 3 Weeks Ago
asandy1234 asandy1234 is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 14
Great thanks Frans

---------- Post updated 11-05-09 at 04:18 PM ---------- Previous update was 11-04-09 at 07:09 PM ----------

Hi Frans,
I really appreciate the time and effort u r spending on this, I've a request, can this code be changed to read from a DB2 table and write to DB2 table?

Thanks,
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:12 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0