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: Michael Cook
Subject: Re: head and file with CR line terminators
Date: Tue, 26 Dec 2023 12:26:35 -0500

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
>
>


reply via email to

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