Skip to content

The Accidental Developer

What if Gregor Samsa awoke a computer programmer?

Pages

  • About

Categories

  • Accessibility
  • Ansible
  • authors
  • AWS
  • Best Practices
  • ColdFusion
  • CSS
  • Debugging
  • Docker
  • Facebook
  • Flash
  • Games
  • Git
  • Google
  • Javascript
  • Monitoring
  • MySQL
  • Oracle
  • perl
  • php
  • Powershell
  • Process
  • python
  • Scala
  • security
  • seo
  • Sharepoint
  • Splunk
  • SysAdmin
  • Testing
  • Tips & Tricks
  • twitter
  • Uncategorized
  • User Interface
  • Video
  • wordpress
  • Workstation
  • xml

Tag: paste

One-liner to convert a file to a comma-delimited list (Bash)

paste -d, -s filename | sed 's/,/","/g' | sed 's/^/"/' | sed 's/$/"/'

Example:

file1.txt contains:
alpha
bravo
charlie
delta
echo

paste -d, -s file1.txt | sed 's/,/","/g' | sed 's/^/"/' | sed 's/$/"/' > file2.txt

file2.txt contains:
"alpha","bravo","charlie","delta","echo"

Posted on 12 Jul 2016Author Chris HerdtCategories Tips & TricksTags bash, paste, sed2 Comments on One-liner to convert a file to a comma-delimited list (Bash)
Proudly powered by WordPress