Skip to main content
added 206 characters in body
Source Link
slm
  • 379.7k
  • 127
  • 793
  • 897

Using Perl:

$ perl -F, -wane 'print "$F[0],$F[-1]"' your_file > new_file 

Also you could use sed since you don't care about anything in the middle, that's essentially everything in between the 2 outside commas, you can do this:

$ sed 's/,.*,/,/g' your_file > new_file

Using Perl:

$ perl -F, -wane 'print "$F[0],$F[-1]"' your_file > new_file 

Using Perl:

$ perl -F, -wane 'print "$F[0],$F[-1]"' your_file > new_file 

Also you could use sed since you don't care about anything in the middle, that's essentially everything in between the 2 outside commas, you can do this:

$ sed 's/,.*,/,/g' your_file > new_file
Source Link
slm
  • 379.7k
  • 127
  • 793
  • 897

Using Perl:

$ perl -F, -wane 'print "$F[0],$F[-1]"' your_file > new_file