![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
|||||
|
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
If this doesn't work, send me a big sample of xml to process |
|
||||
|
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.. |
|
|||||
|
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
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
|
|
||||
|
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, |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|