Skip to navigation

Archive for the 'Bash shell' Category

Replace DOS line feeds (CRLF line terminators) using sed

Wednesday, March 20th, 2013

A sed command stumbled on the fact that a text file came from Windows. file filename.csv gave ASCII text, with CRLF line terminators To fix it: sed -i ‘s/^M//’ filename.csv Where the “^M” is input by pressing Ctrl-V then ENTER. Credits.

Mutt: set dynamic email signature from shell command output

Saturday, October 3rd, 2009

I want to set my signature when mailing to the r-help mailing list to contain information about the R version I have currently installed. Creating a bash script that directly echoes the several lines that I want to have in my signature and executing that in the muttrc using backticks gives a “broken pipe” error. […]

How to use mutt to send individual e-mails to lots of people at once

Wednesday, March 18th, 2009

So, you want to send an e-mail to a list of people, but you don’t want to put them all in the “To:” or the “Bcc:” field of a single mail. You want each person to get an individual e-mail, but with the same subject line and the same content. It’s easy using mutt. Create […]

Filename pattern matching via bash extended globbing and find regular expressions in shell scripts

Tuesday, January 20th, 2009

I was confused that bash would expand some patterns nicely to match filenames when I was on the commandline, but the same pattern would not work from inside a shell script. For example, the following pattern would nicely match all files in the current directory not having an “Rnw” or “tex” extension on the commandline: […]

Removing duplicate lines from a file

Wednesday, January 14th, 2009

Case-insensitive: { rm “$file” && awk ‘!x[tolower($1)]++’ > “$file”; } < "$file" Case-sensitive: { rm "$file" && awk '!x[$1]++' > “$file”; } < "$file" Here's a shell script you could use, as it stands, only works for one file at a time: #!/bin/bash usage() { cat "$filename"; } < "$filename" else { rm "$filename" && […]