Home > Archive > AWK > October 2004 > changing lf-only to crlf
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
changing lf-only to crlf
|
|
| Rufus V. Smith 2004-10-02, 8:56 am |
| Here's a little quickie I've found useful (I'm loving awk!).
I get files that have unix style linefeed-only and I can't edit them in
notepad.
After learning about awk, I just:
gawk "{print $0}" <infile.txt >outfile.txt
and it works like a champ!
Rufus
| |
| Ulrich M. Schwarz 2004-10-02, 8:56 am |
| "Rufus V. Smith" <nospam@nospam.com> writes:
> Here's a little quickie I've found useful (I'm loving awk!).
>
> I get files that have unix style linefeed-only and I can't edit them in
> notepad.
>
> After learning about awk, I just:
>
> gawk "{print $0}" <infile.txt >outfile.txt
Alternatively, you can use the Shortest Program Ever:
gawk 1 infile.txt >outfile.txt
(Just as the empty pattern in your program always matches, the empty
action means "print $0".)
Just for the record.
Ulrich
--
"Stocks of combustible gases, such as carbon dioxide and helium, are
helping to fuel the flames making the blaze highly volatile."
-- Heard on MSNBC by RT, related in the sdm.
also at http://www.msnbc.com/news/954457.asp
| |
| Ian Stirling 2004-10-02, 8:56 am |
| Ulrich M. Schwarz <brotherelf@gmx.net> wrote:
> "Rufus V. Smith" <nospam@nospam.com> writes:
>
>
> Alternatively, you can use the Shortest Program Ever:
> gawk 1 infile.txt >outfile.txt
> (Just as the empty pattern in your program always matches, the empty
> action means "print $0".)
Hmm.
The null program should be a valid awk program shouldn't it?
Never do nothing.
(gawk at least doesn't support it, which bothers me not at all)
| |
| Kenny McCormack 2004-10-02, 8:56 am |
| In article <415dc52f$0$69739$ed2619ec@ptn-nntp-reader01.plus.net>,
Ian Stirling <root@mauve.demon.co.uk> wrote:
....
>The null program should be a valid awk program shouldn't it?
>Never do nothing.
>
>(gawk at least doesn't support it, which bothers me not at all)
"man gawk" contains this text:
Either the pattern may be missing, or the action may be missing, but, of
course, not both.
I find no such language in "man awk" (on Solaris). But it is pretty
obvious, else you couldn't have blank lines in your program...
| |
| Juhan Leemet 2004-10-02, 8:56 am |
| On Fri, 01 Oct 2004 10:18:06 -0400, Rufus V. Smith wrote:
> Here's a little quickie I've found useful (I'm loving awk!).
>
> I get files that have unix style linefeed-only and I can't edit them in
> notepad.
While I like awk and *nix tools, I would never have thought of that. I
used to open any "questionable" files with wordpad, which I found could
read *nix files, and after editing could store them in Windoze format(s).
--
Juhan Leemet
Logicognosis, Inc.
| |
| Ian Stirling 2004-10-02, 8:56 am |
| Kenny McCormack <gazelle@yin.interaccess.com> wrote:
> In article <415dc52f$0$69739$ed2619ec@ptn-nntp-reader01.plus.net>,
> Ian Stirling <root@mauve.demon.co.uk> wrote:
> ...
>
> "man gawk" contains this text:
>
> Either the pattern may be missing, or the action may be missing, but, of
> course, not both.
>
> I find no such language in "man awk" (on Solaris). But it is pretty
> obvious, else you couldn't have blank lines in your program...
It would be a bit of computational overhead, but I can't see any
side-effects.
Thanks for pointing me at that bit of the manual, I somehow missed
it when scanning through.
| |
| Brian Inglis 2004-10-02, 3:55 pm |
| On 01 Oct 2004 20:59:28 GMT in comp.lang.awk, Ian Stirling
<root@mauve.demon.co.uk> wrote:
>Ulrich M. Schwarz <brotherelf@gmx.net> wrote:
>
>Hmm.
>The null program should be a valid awk program shouldn't it?
>Never do nothing.
>
>(gawk at least doesn't support it, which bothers me not at all)
gawk '' <anything or nothing>
just exits quietly (V3.1.1).
--
Thanks. Take care, Brian Inglis Calgary, Alberta, Canada
Brian.Inglis@CSi.com (Brian[dot]Inglis{at}SystematicSW[dot]a
b[dot]ca)
fake address use address above to reply
| |
| Patrick TJ McPhee 2004-10-02, 8:55 pm |
| In article <415dc52f$0$69739$ed2619ec@ptn-nntp-reader01.plus.net>,
Ian Stirling <root@mauve.demon.co.uk> wrote:
% The null program should be a valid awk program shouldn't it?
% Never do nothing.
Leaving aside the question of its validity as an awk program,
although 0 characters is technically shorter than 1 character,
the null program does require more typing, at least using my
tool set.
--
Patrick TJ McPhee
East York Canada
ptjm@interlog.com
| |
| Ulrich M. Schwarz 2004-10-04, 3:55 am |
| "Rufus V. Smith" <nospam@nospam.com> writes:
> Here's a little quickie I've found useful (I'm loving awk!).
>
> I get files that have unix style linefeed-only and I can't edit them in
> notepad.
>
> After learning about awk, I just:
>
> gawk "{print $0}" <infile.txt >outfile.txt
Alternatively, you can use the Shortest Program Ever:
gawk 1 infile.txt >outfile.txt
(Just as the empty pattern in your program always matches, the empty
action means "print $0".)
Just for the record.
Ulrich
--
"Stocks of combustible gases, such as carbon dioxide and helium, are
helping to fuel the flames making the blaze highly volatile."
-- Heard on MSNBC by RT, related in the sdm.
also at http://www.msnbc.com/news/954457.asp
| |
| Ian Stirling 2004-10-04, 8:55 am |
| Ulrich M. Schwarz <brotherelf@gmx.net> wrote:
> "Rufus V. Smith" <nospam@nospam.com> writes:
>
>
> Alternatively, you can use the Shortest Program Ever:
> gawk 1 infile.txt >outfile.txt
> (Just as the empty pattern in your program always matches, the empty
> action means "print $0".)
Hmm.
The null program should be a valid awk program shouldn't it?
Never do nothing.
(gawk at least doesn't support it, which bothers me not at all)
| |
| Stepan Kasal 2004-10-04, 8:55 am |
| Hello,
Ian Stirling wrote:[color=darkred]
> Kenny McCormack <gazelle@yin.interaccess.com> wrote:
Yes, the null program is a valid program, which contains no rules.
Since no rule is evaluated, no action is performed.
The null awk program does nothing.
[color=darkred]
gawk supports it (verified with my 3.1.3, another poster reported that
3.1.1 works fine too).
[color=darkred]
Sure, the empty string is not a rule. (The null program doesn't contain any
``null rule'' it simply has no rules at all.)
If we allowed null rule, we'd get into problems. Null rule would have no
expression, which is equivalent to ``true'' and the ommitied action would
default to ``{print $0}''.
Thus the null rule would print the record. But how many null rules would
the null program contain? And every empty line? And every null string at
the beginning of each non-null rule?
That's why null rules are not allowed, though the null program is.
Hope this explains it,
Stepan Kasal
| |
| Rufus V. Smith 2004-10-04, 3:55 pm |
|
"Ulrich M. Schwarz" <brotherelf@gmx.net> wrote in message
news:hv6032-104.ln1@invisibletruth.510081182724.dialin.t-online.de...
> "Rufus V. Smith" <nospam@nospam.com> writes:
>
>
> Alternatively, you can use the Shortest Program Ever:
> gawk 1 infile.txt >outfile.txt
> (Just as the empty pattern in your program always matches, the empty
> action means "print $0".)
>
> Just for the record.
> Ulrich
> --
> "Stocks of combustible gases, such as carbon dioxide and helium, are
> helping to fuel the flames making the blaze highly volatile."
> -- Heard on MSNBC by RT, related in the sdm.
> also at http://www.msnbc.com/news/954457.asp
Very nice!
Since I obviously type it in each time, the shorter the better.
Thanks Ulrich!
Rufus
P.S. Great signature line! I almost didn't read it and would have lost
out...
One would hope this is a newsgroup wherein most members could
appreciate the humor.
| |
| Stepan Kasal 2004-10-07, 3:55 am |
| Hello,
Ian Stirling wrote:[color=darkred]
> Kenny McCormack <gazelle@yin.interaccess.com> wrote:
Yes, the null program is a valid program, which contains no rules.
Since no rule is evaluated, no action is performed.
The null awk program does nothing.
[color=darkred]
gawk supports it (verified with my 3.1.3, another poster reported that
3.1.1 works fine too).
[color=darkred]
Sure, the empty string is not a rule. (The null program doesn't contain any
``null rule'' it simply has no rules at all.)
If we allowed null rule, we'd get into problems. Null rule would have no
expression, which is equivalent to ``true'' and the ommitied action would
default to ``{print $0}''.
Thus the null rule would print the record. But how many null rules would
the null program contain? And every empty line? And every null string at
the beginning of each non-null rule?
That's why null rules are not allowed, though the null program is.
Hope this explains it,
Stepan Kasal
| |
| Ian Stirling 2004-10-09, 8:55 am |
| Patrick TJ McPhee <ptjm@interlog.com> wrote:
> In article <415dc52f$0$69739$ed2619ec@ptn-nntp-reader01.plus.net>,
> Ian Stirling <root@mauve.demon.co.uk> wrote:
>
> % The null program should be a valid awk program shouldn't it?
> % Never do nothing.
>
> Leaving aside the question of its validity as an awk program,
> although 0 characters is technically shorter than 1 character,
> the null program does require more typing, at least using my
> tool set.
I agree, I was just wondering about if '1' was the shortest program.
Aside from that, I'd say it's probably good style to quote all programs,
if they need it or not.
|
|
|
|
|