2

I'm looking for a shell command to delete the return chariot on one line out of two. I have a file like this :

1.32640997
;;P
1.14517534
;;P
1.16120958
;;P
...

And I would like something like this:

1.32640997;;P
1.14517534;;P
1.16120958;;P
...

Is it possible? Thanks

raikyn
  • 23
  • 2

3 Answers3

3

Using GNU paste

paste -d '' - - < file

Using BSD paste

paste -d '\0' - - < file

paste produces two columns from stdin with - - as parameters, 3 columns with - - - as parameters, and so on.

-d is to specify a column separator, use '\0' for no separator.

Using Perl

perl -ne 'chomp($prev = $_); print $prev, scalar <>' < file
janos
  • 120,954
  • 29
  • 226
  • 236
2

Using awk

$ awk '{printf "%s%s",$0,(NR%2==0?ORS:"")}' File
1.32640997;;P
1.14517534;;P
1.16120958;;P

This prints each line followed by nothing for odd lines or followed by the output record separator for even lines.

Using sed

This works by reading in lines in pairs:

$ sed 'N; s/\n//' File
1.32640997;;P
1.14517534;;P
1.16120958;;P

N reads in the next line and s/\n// removes the newline.

janos
  • 120,954
  • 29
  • 226
  • 236
John1024
  • 109,961
  • 14
  • 137
  • 171
  • For the record, this is better than my `paste` solution, because sed and awk are more widely available (for example no `paste` in Git Bash if I recall correctly) – janos Aug 02 '16 at 08:03
0

Using xargs:

xargs -n 2 -d '\n' printf '%s%s\n' <file
user1934428
  • 19,864
  • 7
  • 42
  • 87