Simple unix script help

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Or more appropriately named: Why the heck doesn't this work?

cat test1.n0c
1

cat dates
20041201
20041202
20041203

cat test1.n0c dates
1
20041201
20041202
20041203

cat test1.n0c dates | tr '\n' ,
1,20041201,20041202,20041203

cat test1.n0c | sed -e 's/1/2/'
2

cat test1.n0c dates | sed -e 's/1/2'
2
20041201
20041202
20041203

cat test1.n0c dates | tr '\n' , | sed -e 's/1/2/'

I'm confused.
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Oh, and if someone can tell me how to insert a "," at the beginning of the file, the problem goes away. :p
 

oog

Golden Member
Feb 14, 2002
1,721
0
0
if a , at the beginning would help, can't you just echo one before passing it to sed? echo "," `cat...` | sed ...

haven't really given any thought to why it doesn't do what you want.
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: oog
if a , at the beginning would help, can't you just echo one before passing it to sed? echo "," `cat...` | sed ...

haven't really given any thought to why it doesn't do what you want.

That might work. I managed to find a way around the whole situation, but I'm still interested in why the situation at the top doesn't work. :p