Re: Join Lines



shulamitm ha scritto:
Hello,

I'm looking for solution to the following problem:

I have a file contains 2 fileds, but in a few rows, the second field
go down (without spaces) to the next line.
How can I join the splitted lines?

For exmple:

I need to change the following :

ERROR1 1
ERROR2 1
WARNING1 0
WARNING2
0
WARNING3
0
ERROR3 1


To:



ERROR1 1
ERROR2 1
WARNING1 0
WARNING2 0
WARNING3 0
ERROR3 1

Thanks in advance!

if you dont mind the whitespace:

~/superpollo$ cat fields.sh
#!/usr/bin/env bash
while read A B
do
echo -n $A" "
if [ -z "$B" ]
then
read B
echo $B
else
echo $B
fi
done
~/superpollo$ cat fields
ERROR1 1
ERROR2 1
WARNING1 0
WARNING2
0
WARNING3
0
ERROR3 1
~/superpollo$ ./fields.sh < fields
ERROR1 1
ERROR2 1
WARNING1 0
WARNING2 0
WARNING3 0
ERROR3 1
~/superpollo$

bye



--
Il valore 96 sarebbe,Volendo, un ipercubo in i.
.



Relevant Pages

  • Re: Join Lines
    ... I have a file contains 2 fileds, but in a few rows, the second field ... echo -n $A" " ... ~/superpollo$ cat fields ... how can I do the same in korn shell or c shell? ...
    (comp.unix.shell)
  • Re: Join Lines
    ... I have a file contains 2 fileds, but in a few rows, the second field ... echo -n $A" " ... ~/superpollo$ cat fields ... how can I do the same in korn shell or c shell? ...
    (comp.unix.shell)
  • revisiting a if -z null/empty string question
    ... I am trying to clean up some user directories on an AIX 5.3 box. ... I've been trying to test for a valid second field in the /tmp/UID.del ... echo "Second field good, so far" ...
    (comp.unix.shell)
  • Re: Join Lines
    ... echo -n $A" " ... ~/superpollo$ cat fields ... how can I do the same in korn shell or c shell? ... misleading shebang unnecessarily set to bash ...
    (comp.unix.shell)
  • Re: Join Lines
    ... echo -n $A" " ... ~/superpollo$ cat fields ... how can I do the same in korn shell or c shell? ... misleading shebang unnecessarily set to bash ...
    (comp.unix.shell)