1849253 Members
5871 Online
104042 Solutions
New Discussion

Text Manipulation .

 
SOLVED
Go to solution
rveri
Super Advisor

Text Manipulation .

Hi All,

I have a file : team1.txt
with the following details,

$ cat team1.txt

John
Christian
Veri
Ronald
------------

I want this to be show in this way ,
$ cat team1.txt
John Christian Veri Ronald

How can I do that , with the help of shell script.

Many Thanks ,
Veri.
16 REPLIES 16
Muthukumar_5
Honored Contributor

Re: Text Manipulation .

awk '{ printf $0" "; } END { print; }' team1.txt

hth.
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor
Solution

Re: Text Manipulation .

Another way as,

# paste -s -d" " team1.txt

hth.
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: Text Manipulation .

To update into the same file then,

# perl -pe 's/\n/ /' team1.txt | perl -pe 's/$/\n/' > team1.txt

hth.
Easy to suggest when don't know about the problem!
Raj D.
Honored Contributor

Re: Text Manipulation .

Hi ,
You can use the tr command also to do that.

Raj.
" If u think u can , If u think u cannot , - You are always Right . "
rveri
Super Advisor

Re: Text Manipulation .

Hi Muthukumar,
The first post with awk command does not work . and giving same output.
Do you know how to get it thru awk also.

Thanks,



Raj D.
Honored Contributor

Re: Text Manipulation .

Hi Veri ,

You can do this using the following tr command:

$ tr -s '/\n' '/ /' < team1.txt

Cheers ,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
sparky_2
Frequent Advisor

Re: Text Manipulation .

Why not use a shell script to do this?
eg.
#!/usr/bin/sh
for x in $(cat team1.txt)
do
print "$x \c"
done
print
#end
sparky_2
Frequent Advisor

Re: Text Manipulation .

PS. Tried it out and Muthukumar's awk command does work -
awk '{printf $0" ";}END {print}' team1.txt
rveri
Super Advisor

Re: Text Manipulation .

Hi Sparky ,

i) Your command rather shell script , works fine , But I dont understand why 2 print given in the script.

ii) Muthukumars perl script works great.

ii) also now Muthukumars awk command also now works fine , after putting printf .



Muthukumar_5
Honored Contributor

Re: Text Manipulation .

If you want to update in to the same file then,

awk '{printf $0" ";}END {print}' team1.txt > temp.txt
mv temp.txt team1.txt

AND,

Your profile says as,

I have assigned points to 126 of 211 responses to my questions.

Try to change to 211 of 211 responses by assigning points ;) It will give more responses and help.

hth.
Easy to suggest when don't know about the problem!
Raj D.
Honored Contributor

Re: Text Manipulation .

what about this one,

$ tr -s '/\n' '/ /' < team1.txt > team2.txt
$ mv team2.txt team1.txt

Cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
rveri
Super Advisor

Re: Text Manipulation .

Thanks Muthukumar , Sparky and Raj,

All above works ,

Thank you.
rveri
Super Advisor

Re: Text Manipulation .

Thanks all,

Muthukumar , "Try to change to 211 of 211 responses by assigning points "

Can you have a look now ..


Thanks all & who replied. Got solution.

rveri
Super Advisor

Re: Text Manipulation .

Got solution. Many Thanks to all.
Muthukumar_5
Honored Contributor

Re: Text Manipulation .

Hi Veri,

Thanks for turning into a user who has given more points than the responses. ;)

It is changed as,

======================================

I have assigned points to 216 of 213 responses to my questions.

======================================

:) Don't know. It is being a problem to some of the users. Post it in the ITRC Forums Issues.

hth.
Easy to suggest when don't know about the problem!
rveri
Super Advisor

Re: Text Manipulation .

Thank you.
------------