× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi Bob,

Grep is a Unix tool. On Unix systems, text files always end in LF (not CRLF). Therefore it seems reasonable that the output of grep would always end in LF rather than CRLF.

I don't understand why you received responses stating that dot doesn't match a newline..? What they say is certainly true, but I can't see what it has to do with your question. Maybe I just don't understand your question?

Aside from that, you're doing some things in your RE that I don't understand:

a) Using a subexpression -- but never recalling it, therefore it's pointless.

b) putting .* at the end -- despite that grep doesn't want/need to match the entire record, and therefore there's no need to say "plus anything after that."

In other words, unless I'm missing something (certainly possible) your grep statement really should look like this:

grep '^[0-9]' ${INPUTFILE} > ${OUTPUTFILE}

This basically says "match every record that starts with a number".

If you have gawk installed (from the GNU utilities offered by IBM -- I think its LPO 5799-PTL, but that's off the top of my head) you could do the following to add the carriage return back to the record:

grep '^[0-9]' ${INPUTFILE} | gawk '{ print $0 "\r" }' > ${OUTPUTFILE}

That's just what popped into my head -- there are probably lots of other ways to do it. If you don't want to install gawk, and can't find another way to do it, you could always write your own (really simple) utility that adds the CR back to the line... this can easily be done in ILE RPG or ILE C.


Bob Schwartz wrote:
I am running the qshell grep command on a csv file.
grep '\(^[0-9]\).*' ${INPUTFILE} > ${OUTPUTFILE}

The input csv file is ccsid 1252 with CRLF characters as end of each
record.

The command selects all the correct records, but removes the CR.

Any seen this before, know why, how to correct?

Thanks, Bob S



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.