9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] trailing newline in awk
@ 2012-01-26 12:15 dexen deVries
  2012-01-26 13:17 ` hugo rivera
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: dexen deVries @ 2012-01-26 12:15 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

hi list,

can't wrap my head around this: in an awk script, how to take some action if a 
file lacks last trailing Line Feed?

i want to modify files with contents like:
text LF
text LF
text

and leave undisturbed files with content like:
text LF
text LF
text LF

in other words, i want to either:
 - match line that is empty and is last line of file (awk doesn't seem to take 
any action on such line), or, alternatively,
 - match a line that is last line of file and lacks terminating LF.

-- 
dexen deVries

[[[↓][→]]]

Already many of the mutants disguised as human beings are walking the streets 
of Earth's cities.
 -- Music Instructor, ``Electro City''



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] trailing newline in awk
  2012-01-26 12:15 [9fans] trailing newline in awk dexen deVries
@ 2012-01-26 13:17 ` hugo rivera
  2012-01-26 13:20 ` Steve Simon
  2012-01-26 15:32 ` Jonathan Cast
  2 siblings, 0 replies; 4+ messages in thread
From: hugo rivera @ 2012-01-26 13:17 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Seems impossible to do in awk, but I could be wrong. In ssam is easy:

% ssam -ne 'y/.+\n/p' file

prints the last line if it's missing the line feed.

2012/1/26 dexen deVries <dexen.devries@gmail.com>:
> hi list,
>
> can't wrap my head around this: in an awk script, how to take some action if a
> file lacks last trailing Line Feed?
>
> i want to modify files with contents like:
> text LF
> text LF
> text
>
> and leave undisturbed files with content like:
> text LF
> text LF
> text LF
>
> in other words, i want to either:
>  - match line that is empty and is last line of file (awk doesn't seem to take
> any action on such line), or, alternatively,
>  - match a line that is last line of file and lacks terminating LF.
>
> --
> dexen deVries
>
> [[[↓][→]]]
>
> Already many of the mutants disguised as human beings are walking the streets
> of Earth's cities.
>  -- Music Instructor, ``Electro City''
>



-- 
Hugo



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] trailing newline in awk
  2012-01-26 12:15 [9fans] trailing newline in awk dexen deVries
  2012-01-26 13:17 ` hugo rivera
@ 2012-01-26 13:20 ` Steve Simon
  2012-01-26 15:32 ` Jonathan Cast
  2 siblings, 0 replies; 4+ messages in thread
From: Steve Simon @ 2012-01-26 13:20 UTC (permalink / raw)
  To: 9fans

Interesting one.

Both sed and awk has treat EOF as a line terminator
so either of these will work:

	awk '{print}' junk
	sed '' junk

but sam doesn't seem to regard a line without a newline as
having an end, so its not simple here:

	{ echo ',x/$?\n/ c/\n/' ; echo '1,$p' } | sam -d junk >[2] /dev/null

-Steve



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] trailing newline in awk
  2012-01-26 12:15 [9fans] trailing newline in awk dexen deVries
  2012-01-26 13:17 ` hugo rivera
  2012-01-26 13:20 ` Steve Simon
@ 2012-01-26 15:32 ` Jonathan Cast
  2 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cast @ 2012-01-26 15:32 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Thu, 2012-01-26 at 13:15 +0100, dexen deVries wrote:
> hi list,
>
> can't wrap my head around this: in an awk script, how to take some action if a
> file lacks last trailing Line Feed?
>
> i want to modify files with contents like:
> text LF
> text LF
> text
>
> and leave undisturbed files with content like:
> text LF
> text LF
> text LF

If this is all you're trying to do,

    awk 1 file

works, no?

jcc





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-01-26 15:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-26 12:15 [9fans] trailing newline in awk dexen deVries
2012-01-26 13:17 ` hugo rivera
2012-01-26 13:20 ` Steve Simon
2012-01-26 15:32 ` Jonathan Cast

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).