The UNIX and Linux Forums  


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 4 Weeks Ago
frans's Avatar
frans frans is online now
Registered User
  
 

Join Date: Oct 2009
Location: Drôme, France
Posts: 105
What a challenge to script that in shell !
Here, i've coded something wich works
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>}
	(( I ++ ))
done
TEXT[$I]=${LINE%</text>*}	# for the last one
{	# To see what we've done
	N=$I
	for I in $(seq $N)
	do	echo "TEXT[$I] = ${TEXT[$I]}"
	done
}
Look if it works by you. If so it's possible to embed it in the appropriate code to parse your files.
  #2 (permalink)  
Old 4 Weeks Ago
asandy1234 asandy1234 is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 14
I get a syntax error
"0403-057 Syntax error at line 10 : `<' is not expected."
  #3 (permalink)  
Old 4 Weeks Ago
frans's Avatar
frans frans is online now
Registered User
  
 

Join Date: Oct 2009
Location: Drôme, France
Posts: 105
try to put quotes around <text> and </text>
like "<text>" "</text>" or '<text>' '</text>'
  #4 (permalink)  
Old 4 Weeks Ago
asandy1234 asandy1234 is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 14
I get different error now.
Document.bash[15]: I ++ : 0403-053 Expression is not complete; more tokens expe
cted
  #5 (permalink)  
Old 4 Weeks Ago
frans's Avatar
frans frans is online now
Registered User
  
 

Join Date: Oct 2009
Location: Drôme, France
Posts: 105
It seems not to be implemented in your shell version
(( I ++ )) means "I=I+1" so try instead
Code:
let I=I+1
  #6 (permalink)  
Old 4 Weeks Ago
asandy1234 asandy1234 is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 14
I changed it but I',m getting something like this..
seq: Not found
  #7 (permalink)  
Old 4 Weeks Ago
frans's Avatar
frans frans is online now
Registered User
  
 

Join Date: Oct 2009
Location: Drôme, France
Posts: 105
try
Code:
# in place of
for I in $(seq $N)
# write
for (i = 1; i < N+1; i++)
or the appropriate code to make a counting loop with your shell
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 06:02 PM.


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