Find and increment at each occurence of string (loop)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find and increment at each occurence of string (loop)
# 8  
Old 02-19-2015
@ RudiC, in that case, why not either VLCV=$[ $VLCV + 1 ] or even just ((VLCV++))?

---------- Post updated at 12:32 ---------- Previous update was at 12:30 ----------

@ TiedCone:
Code:
C=0 # Counter
while [ $C -le $VLCV ]
do  echo "<vlc:item tid=\"$C\"/>"
    C=$(( $C + 1 ))
done

hth

Last edited by sea; 02-19-2015 at 07:37 AM.. Reason: Code fix
# 9  
Old 02-19-2015
Hello Tiedcone,

Following may help you in same, not tested though.
Code:
 awk -vLINES=`cat Input_file | wc -l` 'BEGIN{B=0;C=0} /<vlc:id>/{A=$0;sub(/>.*/,">",$0);sub(/.*</,"<",A);S=S?S ORS $0 B A:$0 B A;print $0 B A;B++;next} /<extension application/{print $0 ORS S;next} 1' Input_file

Thanks,
R. Singh
# 10  
Old 02-19-2015
So - it's in $VLCV, and you are echoing all the text? add
Code:
i=0
while [ "$i" -le "$VLCV" ]
  do echo "           <vlc:item tid=\"$i\"/>"
     i=$(expr $i + 1)
  done

to your script.
# 11  
Old 02-19-2015
Thanks to all. Unfortuantelly I was not able to use above examples but I found another way to achieve my goal by using grep and sed. I just simply copied existing
Code:
<vlc:id>0</vlc:id>

strings and replaced what needs to be replaced. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find and increment value in string of hex

I have a long string of hex (from ASN.1 data) where I need to find and change a particular hex value only and increment it. The hex pairs either side (84 and a7) of the value to increment will remain constant. i.e. "84 <length> <value_to_increment> a7" starting with 00. So end result: ... (11 Replies)
Discussion started by: securegooner
11 Replies

2. Shell Programming and Scripting

Find the occurence of particular string in log file

I have a log file which looks like this: <845185415165:STATUS:5/0:0:0:0:0|ghy59DI5zasldf87asdfamas8df9asd903tGUVSQx4GJVSQ==> I have to extract DATE and number of times the keyword STATUS is shown on each date. Input is : <1354625655744:STATUS:5/0:0:0:0:0|ghy59DI5ztGUVSQx4GJVSQ==>... (8 Replies)
Discussion started by: maddyrox
8 Replies

3. Programming

[Xquery] How to do a increment in a For loop

Hello men. How can i build a simple increment for $a by Xquery such as ? let $a := 0 for $i in (1 to 10) let $a := $a + 1 return $a why a in this loop always is '1' Thank you for reading, its will really helpful for my job if i can solve this problem :D:D (3 Replies)
Discussion started by: tien86
3 Replies

4. UNIX for Dummies Questions & Answers

To find the Nth Occurence of Search String

Hi guys, I like to find the Line number of Nth Occurence of a Search string in a file. If possible, if it will land the cursor to that particualar line will be great. Cheers!! (3 Replies)
Discussion started by: mac4rfree
3 Replies

5. Shell Programming and Scripting

shell script to find the second occurence of the alphabet in a string

this is my assignment question. i'm supposed to submit it tommorow. can somebody please help me with it? Do not post homework questions in the main forums. Please post in the homework forum using the correct template. (0 Replies)
Discussion started by: vijjy
0 Replies

6. Shell Programming and Scripting

find a string in a loop

Hi, Can anyone help with the problem below? I need to read all text files (file1, file2, file3) in a loop and find file1.txt: file2.txt: File3.txt: (7 Replies)
Discussion started by: Lenora2009
7 Replies

7. Shell Programming and Scripting

Find index of last occurence of a character within a string

I need to find the index of last '|' (highlighted in bold) in awk : |ifOraDatabase.Lastservererr<>0then|iferr_flag<>0then|end if Please suggest a way... Thanks (5 Replies)
Discussion started by: joyan321
5 Replies

8. Shell Programming and Scripting

Increment date in 'for' loop?

Hi Guys, My first post..:) Right...I want to move existing files (with some date in their name) currently in $mainftp, to $mainfolder/$foldate/system1. I'd like to be able to increment date in the for loop? Is this possible or should I use a different technique. The script return the... (4 Replies)
Discussion started by: SunnyK
4 Replies

9. Shell Programming and Scripting

How to find vowel's occurence in a string

Hi All, I want to search the string for vowel's occurence and find the no of occurence of each vowels, Could anyone help me out? This is urgent to me...I m new to Shell programming.. Thanks and Regards, Nids:b: (4 Replies)
Discussion started by: Nidhi2177
4 Replies

10. Shell Programming and Scripting

Replace string B depending on occurence of string A

Depending upon the occurence of string 'xyz', I want to remove -t from the input file. There is not a fixed length input file. Any suggestions Input file: this is xyz line -t of the data this is line 2 of -t of the data xyz this is line 3 of -t the file this is line xyz of the -t file... (1 Reply)
Discussion started by: hemangjani
1 Replies
Login or Register to Ask a Question