coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: head and file with CR line terminators


From: Fred H Olson
Subject: Re: head and file with CR line terminators
Date: Tue, 26 Dec 2023 12:17:04 -0600 (CST)

Thanks Michael, I can use that to do what I wanted.
I just wanted to display just one CR terminated lines.
If head could do that it would be nice but probably not worth it.

I dont write perl scripts.  My Linux skill is only moderate (enough to
be dangerous so I use caution and am reluctant when I know I dont know
what I am doing)

Thanks again.  And thanks to all who've worked on and supported
coreutils.

FRed

Musings on these files - feel free to ignore...

CR termination of lines is certainly on the decline I would think
now that mac is *nix based (I'm not very kowledgeable about the Mac world)
(I got to wondering how old (and origin) of the 86 CR files out of 12000 plus
text files on my system. (most have file dates in the 90's, some 2004
and 2 2009) I'd guess that I somehow got a CR file and sometimes
serves as the basis of a series of files.

My editor (semware.com) is configured (currently and for
a long time) to preserve when saving files whatever termination a file
has when loaded. But since these files have not been edited in a long time




On Tue, 26 Dec 2023, Michael Cook wrote:

> If you know the file has CR line terminators, e.g.:
>
> $ file foo
> foo: ASCII text, with CR line terminators
> $ cat -A foo
> hello^Mworld^Mone fish^Mtwo fish^M$
> $
>
> we can use the swiss army knife tool `perl` to show the first line:
>
> $ perl -pe 'BEGIN { $/ = "\r"; $\ = "\n" } chomp; print; exit' <tmp/foo |
> cat -A
> hello$
> $
>
> Does that help?
>
> Or are you asking for a new `head` option that would specify what the line
> terminator is.
>
> Michael
>
> On Tue, Dec 26, 2023 at 11:51 AM Fred H Olson <fholson@cohousing.org> wrote:
>
> > I'm using the command:
> > head -n1
> > on all the 12,000+ text files in my system (!)
> >
> > I have a few with CR line terminators (old Mac files?).
> > I used the command "file" to identify and make a list of text files
> > and created a long linear (12000+ lines) script that does something like:
> >
> > head -n1 <filename1>
> > head -n1 <filename2>
> > etc
> >
> > With this script, if a file has CR line terminators all of
> > the file is printed instead of just the first CR terminated line.
> >
> > From the command line with such a file
> > head -n1 <filename>
> > for one example file that command prints about 100 characters with
> > snippets (10-32 characters long from 6 various CR terminated lines
> > (none of the first (CR) line) is printed.
> >
> > Is there a way (short of reformating such files) to get head to
> > display just one CR terminated line?
> >
> > For now I'll try treating CR terminated lines separately and just print
> > a limited number of bytes.
> >
> > I use my own system of organizing text files and having hyperlink like
> > links between them and am trying to develop a way to make a list such
> > files. I use some "magic" like strings mostly on line one and may try
> > teaching "file" to identify them but for now am examining the first
> > lines of text files
> >
> > I do not subscribe to this list so a direct cc of replies would be
> > appreciated.
> >
> > Fred
> >
> > --
> > Fred H. Olson  Minneapolis,MN 55411  USA        (near north Mpls)
> >      Email:        fholson at cohousing.org      612-588-9532
> > My Link Pg: http://fholson.cohousing.org
> >
> >
>

--
Fred H. Olson  Minneapolis,MN 55411  USA        (near north Mpls)
     Email:        fholson at cohousing.org      612-588-9532
My Link Pg: http://fholson.cohousing.org


reply via email to

[Prev in Thread] Current Thread [Next in Thread]