Unix - combine all rows into a comma-separated single row
问题 I have following values in a file in separate lines: California New York Washington South Carolina Kansas What would be unix script to display them in a single line (as showb below) 'California', 'New York', 'Washington', 'South Carolina', 'Kansas' [I do not want to have any intermediate file to achieve this.. just an echo code is fine] 回答1: Use this command tr '\n' ',' < input_file For single quotes use sed -e "s/^/'/" input_file | sed -e "s/$/'/" | tr '\n' ',' (Not tested for single/double