Find a string across line break (because of "segmentation fault core dumped")


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Find a string across line break (because of "segmentation fault core dumped")
# 1  
Old 11-23-2014
Hammer & Screwdriver Find a string across line break (because of "segmentation fault core dumped")

Hi,
thanks to a precedent post, and thanks to the reply of derekludwig of the forum, I have convert my first awk command as :

test.txt is : AAAAAGHIJKLAjKMEFJKLjklABCDJkLEFGHIJKL

Code:
awk -f findstring.awk test.txt > textreturn.txt

findstring.awk is :

Code:
BEGIN{ SLENGTH = 3 }
{
    
    skipped = 0
    starts = ""
 line   = tolower($0)
    while ( SSTART = index(line,string )) {
        starts = starts (starts?" ":"") (skipped + SSTART)
        line = substr(line,SSTART + SLENGTH)
        skipped += (SSTART + SLENGTH - 1)
    }
}
starts { print starts }

to find all "JKL" regular expression anyway the type of case. It returns 9 18 21 28 36.

Now, I would like to know if it is possible to find this string across different lines and obtain the first result, for example with test.txt like this :

AAAAAGHI
JKLAjKMEFJK
LjklABCDJkLEFGHIJKL

I have tried to transform input file as a unique line with this command :

Code:
awk -vRS="" ' {gsub("\n","",$0) ; print ""$0""} test.txt > test2.txt

But my file is so heavy that I receive this error :
Code:
segmentation fault (core dumped)

I have also tried this one :
Code:
cat test.txt | xargs |sed -e 's/ //g' > test2.txt

and it seems to be works (no messages).

But, by exploring the result file for one heavy file, not all lines are in one line; there is just less number of lines.

Thanks for your help,
Bye.
# 2  
Old 11-23-2014
Wizard,

Just to confirm, using RS="" was to read in stanzas - groups of lines separated by blank lines. Or are you trying to read in the entire file at once? The latter is what you are trying to do with:
Code:
cat test.txt | xargs |sed -e 's/ //g' > test2.txt

which really should be:
Code:
tr -d '\n' < test.txt > test2.txt

This is because xargs will join the lines of text until the maximum number of arguments or maximum command line length is reached.
Perl's file slurping may be useful here:
Code:
perl -e '$/ = undef; $\ = "\n"; $, = " "; $_ = <>; s{\s+}{}g; push @X, pos while m{jkl}gi; print @X;'

which generates:
Code:
11 20 23 30 38 69 80 92 99 107 121 132

for the followig input file:
Code:
AAAAAGHI
JKLAjKMEFJK
LjklABCDJkLEFGHIJKL

ZZAjdskljfdAAAAGHI
ldjkflfsdkJKLAjKMEFJK
jklfsdkjfsdLjklABCDJkLEFGHIJKL

dAAAAGHI
ldkJKLAjKMEFJK
jklfklAB

---------- Post updated at 01:34 PM ---------- Previous update was at 01:31 PM ----------

Or if you don't mind each indice being on a separate line, this is slightly simpler:
Code:
perl -e '$/ = undef; $\ = "\n"; $_ = <>; s{\s+}{}g; print pos while m{jkl}gi;'

# 3  
Old 11-23-2014
Thanks again !

Dear derekludwig,
read all lines of the entire file at once was my goal.
I had tried this command tr, but in wrong way I see, because you have written < test.txt > test2.txt, not me (I had just written test.txt > test2.txt).
And I haven't tried to use Perl language because is again another form of coding for me.
Your answer is very good, I have tested it, and it is very fast.
So, thank you again for your answer and your easy understanding of my problem.
I'm a PhD student (french), I had this problem since Monday. Thanks to you, I can perform my work this night, and forget this nightmare. I need to send the result of my work before the end of the next week. Thanks to you, I'm able to make it.
So, really, thank you so much.
Have a good evening !!
Hope to don't disturb you again before midnight ! Smilie
Bye.
# 4  
Old 11-23-2014
Wizard,

Glad to help.

- Derek
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX and Linux Applications

Tilda Segmentation fault (core dumped)

Can anyone tell me why I keep getting a Segmentation fault when I try to run tilda? $ tilda Segmentation fault (core dumped) It seemed to run after I deleted my tilda directory like this thread said to do. Unfortunately it wouldn't let me set my keybinding with anything I tried. ... (0 Replies)
Discussion started by: cokedude
0 Replies

2. UNIX for Advanced & Expert Users

Segmentation Fault/ core dumped in metadb

When I was trying to mirror in my v880 server after OS up gradation from 8 to 10 metadb -afc 3 /dev/dsk/c1t1d0s7 I got an error metadb: Segmentation Fault Segmentation Fault (core dumped) Then I logged a case to Oracle/sun team they suggest "Please could you try metadb -ac 3... (0 Replies)
Discussion started by: taherahmed
0 Replies

3. Programming

getting Segmentation Fault (core dumped) error but Program runs fine.

i am executing following program int main() { char str; FILE * fp; int i=0; ... (4 Replies)
Discussion started by: bhavesh.sapra
4 Replies

4. Red Hat

Segmentation fault (core dumped)

Hi All, I am getting "Segmentation fault (core dumped)" error in the runtime. I am new this please can you tell me why is that i am getting this error and I am not sure of my compilation : gcc -c avc_test.c gcc -c md5.c gcc avc_test.o md5.o -shared -Llibcoreavc_sdk.so -o proj ... (1 Reply)
Discussion started by: fido.genial
1 Replies

5. Solaris

segmentation fault core dumped

i am getting segmentation fault (core dumped) i tried following things but couldn't understand what is wrong with my prog and where the problem is.... i have only adb debugger available on solaris.... so plz help bash-3.00$ pstack core core 'core' of 765: ./mod_generalised_tapinread... (4 Replies)
Discussion started by: junaid.nehvi
4 Replies

6. Solaris

Segmentation Fault (core dumped)

i am getting Segmentation Fault (core dumped) on solaris, but when i run the same program with same input on linux it runs successfully. How can i trace the fault in program on solaris. (6 Replies)
Discussion started by: junaid.nehvi
6 Replies

7. Programming

Segmentation Fault (core dumped)

what r the situations to receive an error msg like the one below Segmentation Fault (core dumped) (2 Replies)
Discussion started by: bankpro
2 Replies

8. Programming

why tell "core dumped"?

why tell core dumped? I am a new .I write a program.I use cc to complier it. when i run it,it tell me "core dumped"? who can tell me the reason? the program as follow: main() { char *a; printf("please input your name:"); scanf("%s",a); printf("\n"); printf("%s",a); } (3 Replies)
Discussion started by: fresh
3 Replies

9. Programming

What is an "Illegal Instruction -Core Dumped"

Hai! i am working on Digital UNIX V3.2c Work station, my program uses Pro*C, C and X-Motif calls. i am facing problem while running application saying "Illegal Instruction Core Dumped". debugger dbx shows error at a line which shows "noname". when commenting large portion of the code it runs... (1 Reply)
Discussion started by: samn
1 Replies

10. UNIX for Dummies Questions & Answers

Segmentation fault (core dumped)

Hello To All! Now anfd then I receive a message on my console: Segmentation fault (core dumped) What does it mean? Or more precisely what are the implications? :confused: (1 Reply)
Discussion started by: Ivo
1 Replies
Login or Register to Ask a Question