2009/6/16 david <[email protected]>

> Q1. why does sed lose the first line?
>
> da...@david:~/test$ cat blah
> the quick
> brown fox jumps
> over
> the lazy
> dog
> da...@david:~/test$ cat blah | while read line ; do sed s/t/T/ ; done
> brown fox jumps
> over
> The lazy
> dog
> da...@david:~/test$
>


I'll have stab, though I've probably got this slightly wrong.
cat blah puts stuff into stdout.
This gets piped into stdin using your pipe '|'.
The 'while' is just a loop; it runs 'read' which opens stdin so it reads in
the first line of blah into $line.   Having read a line in, the while loop
moves on to the 'sed s/t/T/' line which also opens up stdin and reads the
rest of blah which it then dutifully substitutes (I guess the thing to note
is that 'read' reads a line at a time, but 'sed' just slurps up whatever
lines are available).  stdin has now been totally read - the first line by
'read' and the rest by 'sed'.  'sed' dumps stuff to the stdout but 'read'
doesn't which is why you don't see the top line.

Try running 'sed s/t/T/' by itself; it will sit their patiently waiting for
you to type lines into the terminal.

This would work:

   cat blah | while read line; do echo $line | sed s/t/T/; done

Each line of your file gets put into $line and then echoed into sed.

Or
   cat blah | sed s/t/T/
or, without cat:
   sed s/t/T/ <blah

Or just
   sed s/t/T/ blah

I tend to use -e to specify the script:: sed -e 's/t/T/' ...


> Q2. what does the @ mean?
>
> da...@david:~$ date -d @1174306440
> Mon Mar 19 23:14:00 EST 2007
>
> I got this from a google search - the string is from a mysql timestamp
> which didn't include the @     I can't find a reference to @ in the date man
> page.
>

This isn't a bash thing but a 'date' command thing.
I checked this using the 'info' utility.  Alot of gnu utilities like 'date'
have detailed documentation using the info system - more detailed than their
man pages.
(you type 'info date' - but you may need to install 'info' on your system).
It says that it is the number of seconds since an epoch which for unix
systems is taken to be
1970-01-01 00:00:00 UTC .

date -d @1 would be 1970-01-01 00:00:01 UTC,
My system is outputting as EST so it's more like 10am.


-- 
Daniel Bush

http://blog.web17.com.au
http://github.com/danielbush
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to