Skip to main content
added 3 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Changing some lines into a single line is done with paste -s.

In this case, you want to change four lines into a single line. The four lines are created with seq 1 3; echo 4:

$ seq 1 3; echo 4
1
2
3
4

Pass these through paste -d ' ' -s - to convert them into a single line, delimiting each original line with a space character:

$ { seq 1 3; echo 4; } | paste -d ' ' -s -
1 2 3 4

You could pass the lines through tr '\n' ' ' instead of through paste -s, but this would also replace the final newline character with a space (the one after 4), which is probably not what you want to do.

Changing some lines into a single line is done with paste -s.

In this case, you want to change four lines into a single line. The four lines are created with seq 1 3; echo 4:

$ seq 1 3; echo 4
1
2
3
4

Pass these through paste -d ' ' -s - to convert them into a single line, delimiting each original line with a space character:

$ { seq 1 3; echo 4; } | paste -d ' ' -s -
1 2 3 4

Changing some lines into a single line is done with paste -s.

In this case, you want to change four lines into a single line. The four lines are created with seq 1 3; echo 4:

$ seq 1 3; echo 4
1
2
3
4

Pass these through paste -d ' ' -s - to convert them into a single line, delimiting each original line with a space character:

$ { seq 1 3; echo 4; } | paste -d ' ' -s -
1 2 3 4

You could pass the lines through tr '\n' ' ' instead of through paste -s, but this would also replace the final newline character with a space (the one after 4), which is probably not what you want to do.

added 3 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Changing some lines into a single line is done with paste -s. 

In this case, you want to change four lines into a single line.

The The four lines are created with seq 1 3; echo 4.:

$ seq 1 3; echo 4
1
2
3
4

Pass these through paste -d ' ' -s - to convert them into a single line, delimiting each original line with a space character:

$ { seq 1 3; echo 4; } | paste -d ' ' -s -
1 2 3 4

Changing some lines into a single line is done with paste. In this case, you want to change four lines into a single line.

The four lines are created with seq 1 3; echo 4.

Pass these through paste -d ' ' -s - to convert them into a single line, delimiting each original line with a space character:

$ { seq 1 3; echo 4; } | paste -d ' ' -s -
1 2 3 4

Changing some lines into a single line is done with paste -s. 

In this case, you want to change four lines into a single line. The four lines are created with seq 1 3; echo 4:

$ seq 1 3; echo 4
1
2
3
4

Pass these through paste -d ' ' -s - to convert them into a single line, delimiting each original line with a space character:

$ { seq 1 3; echo 4; } | paste -d ' ' -s -
1 2 3 4
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Changing some lines into a single line is done with paste. In this case, you want to change four lines into a single line.

The four lines are created with seq 1 3; echo 4.

Pass these through paste -d ' ' -s - to convert them into a single line, delimiting each original line with a space character:

$ { seq 1 3; echo 4; } | paste -d ' ' -s -
1 2 3 4