Computing.Net > Forums > Unix > problems with sed

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

problems with sed

Reply to Message Icon

Name: mgonzalo
Date: October 5, 2005 at 03:50:19 Pacific
OS: SunOs isis 5.8
CPU/Ram: Generic_108528-15
Comment:

I have the following file aa1

uno
dos
tres
cuatro

and I want to have it as

uno dos tres cuatro

I make the following thing:

sed '1,$j' aa1

and he responds me

sed: command garbled: 1,$j

as I can make it?

"La experiencia es algo maravilloso. Nos permite reconocer un error cada vez que lo volvemos a cometer.", Franklin P. Jones




Sponsored Link
Ads by Google

Response Number 1
Name: Jim Boothe
Date: October 5, 2005 at 07:18:36 Pacific
Reply:

sed -e :a -e '$!N;s/\n/ /;ta' aa1
uno dos tres cuatro

echo `cat aa1`
uno dos tres cuatro

echo $(cat aa1)
uno dos tres cuatro

cat aa1 | xargs
uno dos tres cuatro

(Credit nails for the last solution)
In the absense of a specified command, xargs defaults to the echo command.


0

Response Number 2
Name: nails
Date: October 5, 2005 at 09:44:44 Pacific
Reply:

Another way is to use the tr command to replace new-lines with spaces:

tr '\n' ' ' < aa1



0

Response Number 3
Name: Jim Boothe
Date: October 5, 2005 at 10:44:26 Pacific
Reply:

And probably the best way.

Thanks nails, I keep forgetting about tr.


0

Response Number 4
Name: mgonzalo
Date: October 6, 2005 at 02:19:05 Pacific
Reply:

thank you Jim Boothe and nails for your answers to tell you that they have given me problems the following ones:

sed -e :a -e '$!N;s/\n/ /;ta' aa1

N;s /: Event not found


echo $(cat aa1)

Variable syntax

"La experiencia es algo maravilloso. Nos permite reconocer un error cada vez que lo volvemos a cometer.", Franklin P. Jones


0

Response Number 5
Name: Jim Boothe
Date: October 6, 2005 at 05:53:47 Pacific
Reply:

Well, that echo is korn/bash shell syntax (sorry, should have mentioned that).

But I would have expected the sed command to work. The sed command that you reposted is correct.

What shell are you using?
echo $SHELL

If you have korn shell available, invoke a korn shell by typing ksh, then try both of those commands and report the results.

Thanks.


0

Related Posts

See More



Response Number 6
Name: mgonzalo
Date: October 14, 2005 at 04:18:41 Pacific
Reply:

I have cshell I will prove with korn shell

"La experiencia es algo maravilloso. Nos permite reconocer un error cada vez que lo volvemos a cometer.", Franklin P. Jones


0

Response Number 7
Name: mgonzalo
Date: October 14, 2005 at 04:30:48 Pacific
Reply:

I have proven with kshell and it works perfectly.
Thank you


"La experiencia es algo maravilloso. Nos permite reconocer un error cada vez que lo volvemos a cometer.", Franklin P. Jones


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: problems with sed

Problem with sed www.computing.net/answers/unix/problem-with-sed/3990.html

Problem with SED www.computing.net/answers/unix/problem-with-sed/7348.html

sed problem with regular expression www.computing.net/answers/unix/sed-problem-with-regular-expression/6876.html