Reading between a repeated string


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Reading between a repeated string
# 8  
Old 04-14-2015
Thanks MadeInGermany

I have tried something like

Code:
ls /data/abc/txt | awk '#ZENCO/{x="#ZENCO"++i;}{print > x;}'

I found the code online and didn't work well.

My requirement is I need to get lines in between repeating #ZENCO each time.

In ETL tool we only have permission to use single line Unix commands.

From ETL tool I can count how many times #ZENCO is repeating and I can also add #ZENCO at header if that makes code any easy.

I can pass the count value of #ZENCO as parameter.

So, when I first run the command, I need records between first #ZENCO and Second #ZENCO,

Second time when I run the command, I need records between Second #ZENCO and Third #ZENCO

and so on... I hope this is clear.
# 9  
Old 04-14-2015
Note that MadeinGermany's suggestion uses m as a parameter, so it seems to be already doing what you require..
Code:
$ awk '/#ZENCO/ {if (++c>m) exit; next} (c==m)' m=1 abc.txt
3
4
5
6
$ awk '/#ZENCO/ {if (++c>m) exit; next} (c==m)' m=2 abc.txt
11
213
454
7
$

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to grep repeated string on the same line?

I have this a file.txt with one line, whose content is /app/jdk/java/bin/java -server -Xms3g -Xmx3g -XX:MaxPermSize=256m -Dweblogic.Name=O2pPod8_mapp_msrv1_1 -Djava.security.policy=/app/Oracle/Middleware/Oracle_Home/wlserver/server/lib/weblogic.policy -Djava.security.egd=file:/dev/./urandom... (3 Replies)
Discussion started by: Lam
3 Replies

2. Shell Programming and Scripting

How to extract every repeated string between two specific string?

Hello guys, I have problem with hpux shell script. I have one big text file that contains like SOH bla bla bla bla bla bla ETX SOH bla bla bla ETX SOH bla bla bla ETX What I need to do is save first SOH*BLA into file1.txt, save second SOH*BLA into file2.txt and so on.... (17 Replies)
Discussion started by: sembii
17 Replies

3. Shell Programming and Scripting

Find repeated word and take sum of the second field to it ,for all the repeated words in awk

Hi below is the input file, i need to find repeated words and sum up the values of it which is second field from the repeated work.Im trying but getting no where close to it.Kindly give me a hint on how to go about it Input fruits,apple,20,fruits,mango,20,veg,carrot,12,veg,raddish,30... (11 Replies)
Discussion started by: 100bees
11 Replies

4. Shell Programming and Scripting

Reading XML and replacing a string

Hi All, My thanks in advance for you guys reading this and for any posts. I'm having 100 XML files, I need script which replace a specific string. It must be incrementing in 100 xml files.. Sample XML files: <hwIPHostName type="attrib">DEMO1</hwIPHostName> I need Demo1 to be... (4 Replies)
Discussion started by: karty2129
4 Replies

5. Shell Programming and Scripting

remove anything after repeated string pattern found

HI, Can anyone help me with a script. i/p calc 1 2 3 4 5 6 7 8 calc 4 5 6 calc 7 8 9 o/p calc 1 2 3 4 5 6 7 8 calc 4 5 6 i.e remove anything after where two times the string calc is found. thanks (3 Replies)
Discussion started by: Indra2011
3 Replies

6. Shell Programming and Scripting

How to find repeated string in a text file

I have a text file where I need to find the string = ST*850* This string is repetaed several times in the file, so I need to know how many times it appears in the file, this is the text files: ISA*00* *00* *08*925485USNR *ZZ*IMSALADDERSP... (13 Replies)
Discussion started by: cucosss
13 Replies

7. Shell Programming and Scripting

reading a .dat file in to a string

i have folowing code. i dont want data in an array. i like to put my data file info (after filtering and converting to lower case) in to a string call "name". so it would look like this, name= ffjtgj345 thgkty3 456gfhf rhtfn4 ...... how do i do that? i dont want to read # or blank lines. ... (13 Replies)
Discussion started by: usustarr
13 Replies

8. Programming

Count the number of repeated characters in a given string

i have a string "dfasdfasdfadf" i want to count the number of times each character is repeated.. For instance, d is repeated 4 times, f is repeated 4 times.. can u give a program in c (1 Reply)
Discussion started by: pgmfourms
1 Replies

9. Shell Programming and Scripting

reading and reversing a string

Hi Everyone....I am new to Unix and BASH programming...I just want to read a string and reverse it and display.....can anyone help me out???? (8 Replies)
Discussion started by: nikhilneela
8 Replies

10. Shell Programming and Scripting

reading a string characterwise

hi , I am trying to read two strings character by character using arrays but i couldn't do it pls.give a solution (2 Replies)
Discussion started by: akmtcs
2 Replies
Login or Register to Ask a Question