Operating System - HP-UX
1753409 Members
7271 Online
108793 Solutions
New Discussion юеВ

Re: Deleting a space in a line during a for ...

 
SOLVED
Go to solution
Manuales
Super Advisor

Deleting a space in a line during a for ...

Hi ..
this is my program..

for x in `cat temp1.${a}`
do
echo "this is the line $x"
done
this is the file temp1.${a}:
=======================
Daniela Miranda
PedroRamirez Lopez
ArturoLimaper
=======================
how can i delete the space when i am taking the line during the for:

for x in `cat temp1.${a}`

i need it be showed the line with no spaces as:
.....................
DanielaMiranda
PedroRamirezLopez
ArturoLimaper
.....................


please let me know.
Thanks in advance.
Manuales.
6 REPLIES 6
James R. Ferguson
Acclaimed Contributor
Solution

Re: Deleting a space in a line during a for ...

Hi:

One way:

#!/usr/bin/sh
while read LINE
do
X=$(echo ${LINE}|tr -d " ")
echo "this is the line: ${X}"
done < temp1/${a}

Regards!

...JRF...
Johnson Punniyalingam
Honored Contributor

Re: Deleting a space in a line during a for ...

I would like you use

=======================
Daniela_Miranda
PedroRamirez_Lopez
Arturo_Limaper
=======================

instud of space i will look for _ in script to delete

Hope this Helps
Problems are common to all, but attitude makes the difference
Raj D.
Honored Contributor

Re: Deleting a space in a line during a for ...

Manuales,

Try this:


for x in `cat temp1.${a}| tr -d " "`
do
....


Cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
Dennis Handly
Acclaimed Contributor

Re: Deleting a space in a line during a for ...

>how can I delete the space

If you want to do other changes, you can modify JRF's solution to use sed(1):
while read LINE; do
X=$(echo ${LINE} | sed -e 's/ //g')
echo "this is the line: ${X}"
done < temp1/${a}

Or change Raj's to remove that evil cat:
for x in $(tr -d " " < temp1.${a}); do

Note if there are other whitespaces in the lines, each $x will not contain the whole line.
Raj D.
Honored Contributor

Re: Deleting a space in a line during a for ...

Thx Dennis, for puting the evil cat under subshell parenthesis , to parse it corrctly.

(0 or 1 pts. only pls. )
" If u think u can , If u think u cannot , - You are always Right . "
Manuales
Super Advisor

Re: Deleting a space in a line during a for ...

thanks all for your support ..

this worked:
for x in `cat temp1.${a}| tr -d " "`

the other examples also worked ..
thank you so much.