Home > Archive > AWK > January 2006 > Append to previous line if line ends with -
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Append to previous line if line ends with -
|
|
| burkina 2006-01-10, 3:58 am |
| Dear all,
I have a file with some lines ending with the minus sign ("-").
I need to append the following line to the line, if this ends with -. I
tried to eliminate the newline char with awk, but didn't succed.
The file is like this one:
259.765533 259.765533 259.765533 259.766022 259.770325 259.756989
259.649628-
259.608032 259.571381 259.578644 259.646057 259.814117 259.958008
260.084534-
260.329102 260.453522 260.766083 261.103699 261.405121 261.690399
261.935974-
261.983154 262.097229 325.628143 324.821747 324.412079 324.479218
324.092316-
322.912964 322.120209 320.396545 319.260681 319.515808 321.214417
323.874481-
264.634735 264.785217 338.487793 338.489655 338.383942 338.384003
338.384003-
338.383942 375.625 382.076263 343.581024 339.971375 339.534119
339.204193-
338.383911 338.383911
259.501312 259.501312 259.501312 259.515961 259.527374 259.475983
259.274963-
259.243774 259.210724 259.235321 259.394989 259.680603 259.626099
259.790222-
260.003021 260.265015 261.702576 261.696655 261.174072 261.4245
261.619385-
261.669067 261.690369 261.654694 323.6828 323.701202 324.009613
324.108429-
323.40387 322.146271 320.545746 319.301636 318.636719 318.400696
323.124878-
324.112885 264.21524 338.507812 338.505463 338.384033 338.384155
338.384125-
338.384125 377.991394 362.469666 358.296997 344.468903 341.669128
346.023102-
338.383911 338.383911
For example, the first 8 lines must be a single, long line, i.e. the
"-\n" at the end of the line should be substituted with a space " ".
How can I do that?
Thanks,
Stefano
| |
| Ed Morton 2006-01-10, 3:58 am |
| burkina wrote:
> Dear all,
>
> I have a file with some lines ending with the minus sign ("-").
> I need to append the following line to the line, if this ends with -. I
> tried to eliminate the newline char with awk, but didn't succed.
> The file is like this one:
>
> 259.765533 259.765533 259.765533 259.766022 259.770325 259.756989
> 259.649628-
> 259.608032 259.571381 259.578644 259.646057 259.814117 259.958008
> 260.084534-
> 260.329102 260.453522 260.766083 261.103699 261.405121 261.690399
> 261.935974-
> 261.983154 262.097229 325.628143 324.821747 324.412079 324.479218
> 324.092316-
> 322.912964 322.120209 320.396545 319.260681 319.515808 321.214417
> 323.874481-
> 264.634735 264.785217 338.487793 338.489655 338.383942 338.384003
> 338.384003-
> 338.383942 375.625 382.076263 343.581024 339.971375 339.534119
> 339.204193-
> 338.383911 338.383911
> 259.501312 259.501312 259.501312 259.515961 259.527374 259.475983
> 259.274963-
> 259.243774 259.210724 259.235321 259.394989 259.680603 259.626099
> 259.790222-
> 260.003021 260.265015 261.702576 261.696655 261.174072 261.4245
> 261.619385-
> 261.669067 261.690369 261.654694 323.6828 323.701202 324.009613
> 324.108429-
> 323.40387 322.146271 320.545746 319.301636 318.636719 318.400696
> 323.124878-
> 324.112885 264.21524 338.507812 338.505463 338.384033 338.384155
> 338.384125-
> 338.384125 377.991394 362.469666 358.296997 344.468903 341.669128
> 346.023102-
> 338.383911 338.383911
>
> For example, the first 8 lines must be a single, long line, i.e. the
> "-\n" at the end of the line should be substituted with a space " ".
> How can I do that?
>
> Thanks,
>
> Stefano
>
In gawk:
awk -v RS="-\n" -v ORS=" " '1'
Regards,
Ed.
| |
| burkina 2006-01-10, 3:58 am |
| Ed Morton worte:
>In gawk:
>awk -v RS="-\n" -v ORS=" " '1'
Thanks!
The only problems is that, even using "" instead of " ", it (obviously)
keeps a white space more bacause the other lines begin with two white
spaces....
Cheers,
Stefano
| |
| burkina 2006-01-10, 3:58 am |
| Ed Morton wrote:
>In gawk:
>awk -v RS="-\n" -v ORS=" " '1'
Thanks!
The only problems is that, even using "" instead of " ", it (obviously)
keeps a white space more bacause the other lines begin with two white
spaces....
Cheers,
Stefano
| |
| Ed Morton 2006-01-10, 3:58 am |
| burkina wrote:
> Ed Morton wrote:
>
>
>
>
> Thanks!
> The only problems is that, even using "" instead of " ", it (obviously)
> keeps a white space more bacause the other lines begin with two white
> spaces....
Then stick a couple of spaces in the RS:
awk -v RS="-\n " -v ORS=" " '1'
or just one and change the ORS accordingly:
awk -v RS="-\n " -v ORS= '1'
In this particular case, setting the variables after the awk body would
work too, if you want the briefest script:
awk 1 RS="-\n " ORS= file
Regards,
Ed.
|
|
|
|
|