Search for a pattern

If you transfer a file in binary mode it also copies the hex x0D characters at the end of the lines.
In DOS/Windows text files a line ends with CR/LF while on *nix systems a line ends with a LF (hex 0A).
You can converse the file if you have the utility dos2ux on your system.
An alternative is:

tr -d \\r < win.txt > unix.txt

Regards

I will have to think about the following:

sed 's/$pattern_da_cercare/$pattern_da_cercare \n/g' $zf >tempf

This is now a sed issue on inserting a line feed to force a new line

if pattern="smith"
...it should replace

with

prior to the
numpat=$(cat tempf | grep "$pattern_da_cercare" | wc -l)

So, what changes I have to do to make the script work?

sed 's/$pattern_da_cercare/$pattern_da_cercare \n/g' $zf >tempf

That command is not inserting a blank line after each $pattern_da_cercare as I thought it should.

Try to research into sed to insert a blank line.

I tryed to research how to insert into sed a blanck line but I wasn't succeed.

Doe anyone know how to do it?

I got lost going through this thread. But the final question seems to be:

$ echo "abc abc abc" | sed 's/abc/abc\
> /g'
abc
 abc
 abc

$

The backslash is the thing on the first line so sed sees a backslash newline. I need a "g" at the end of sed s command to operate on all occurences of "abc".

or use tr to ceate a list with one word per line, then the grep to count:

e.g.

tr -cs "[:alpha:]" "[\n*]" < infile | grep -cw searchstring