Reading between a repeated string


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Reading between a repeated string
# 1  
Old 04-13-2015
Reading between a repeated string

I have a requirement where I have to read the lines between a repeated string

FileName: abc.txt

Code:
ls /data/abc.txt

1
2
#ZENCO
3
4
5
6
#ZENCO
11
213
454
7
#ZENCO

I need to output this 3 times based on #ZENCO

How to get data between #ZENCO. I can add #ZENCO as header but how to read data between a particular string.
# 2  
Old 04-13-2015
Your request is ambiguous. What output are you hoping to produce?

Do you have an alias for ls that echoes an empty line and then performs a cat? Or, is the line starting with ls part of the data contained in abc.txt?
# 3  
Old 04-13-2015
Sorry, ls is not part of data.

It's just path where file exist.

---------- Post updated at 04:18 PM ---------- Previous update was at 04:15 PM ----------

So, if I need lines from first #ZENCO to #ZENCO, how would I do it and similarly if I need to get lines from third #ZENCO to #ZENCO how would I get it.


Just need a common command, I can pass the valued at runtime with the etl tool
# 4  
Old 04-13-2015
Please give us details; not nebulous requirements.
  1. What operating system and shell are you using? (And "etl tool" is not the name of a shell.)
  2. Tell us what operands you want to pass to this script.
  3. Show us what output you want from this script. (Is the output inclusive of the #ZENCO lines, or exclusive of those lines?)
  4. Do you always want to capture the lines between the nth and the n+1st occurrence of #ZENCO, or are you trying to capture the lines between the nth and the mth occurrences?
  5. Should it be an error (with no output but a diagnostic) if the requested occurrences of #ZENCO are not present in the data, or should you just get the subset of the input that matches your criteria even if it is the empty set?
  6. If this is an etl problem, can't you query your database for this information?
  7. What have you tried to solve this problem yourself?
# 5  
Old 04-14-2015
The output I need is

3
4
5
6
# 6  
Old 04-14-2015
I have no idea how you would get those 5 lines of output from the sample input you provided. And, you refused to answer most of the questions I asked. So, we have to assume that you have not made any attempt to solve this problem on your own, are not interested in learning how to solve problems on your own, and are only interested in using this forum as your unpaid programming staff.

So, here is a simple command that will produce the output you said you want on any operating system using any shell as long as you have permission to read your input file:
Code:
print "%s\n" "" 3 4 5 6 < /data/abc.txt

# 7  
Old 04-14-2015
Lines between m=1 and the following occurrence of the string:
Code:
awk '/#ZENCO/ {if (++c>m) exit; next} (c==m)' m=1 abc.txt

This User Gave Thanks to MadeInGermany For This Post:
 
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