Skip to content

Instantly share code, notes, and snippets.

@cdolek
cdolek / dropbox
Created October 3, 2017 02:12 — forked from thisismitch/dropbox
/etc/init.d/dropbox
#!/bin/sh
### BEGIN INIT INFO
# Provides: dropbox
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Interactive: false
# Short-Description: dropbox service
### END INIT INFO
@cdolek
cdolek / gist:38d7f69f5ae24144d548b798ec81e5d5
Last active June 15, 2017 19:08
Rename spaces in the files and directory names found in a directory to _ underscore
for f in *\ *; do mv "$f" "${f// /_}"; done
@cdolek
cdolek / gist:700f5e3cd2791297df8f271ef909b6e6
Created June 14, 2017 22:32
Get links from html file
sed -n 's/.*href="\([^"]*\).*/\1/p' *.html >> somefile.txt
@cdolek
cdolek / gist:b14421777b688724e942f72aec065f1c
Created June 5, 2017 22:33
getting all string after nth character
**from,to**
awk '{print substr($0,24,999999)}' my.csv
@cdolek
cdolek / gist:721339e189dd3d33921d817bb955060a
Created June 3, 2017 00:26
Filter CSV by length of string in a column
# Gets line if string in the first column is longer than 6
cat file.csv | awk -F "," 'length($1)>6' > file_longerthan6chars.csv
@cdolek
cdolek / gist:27d180a2523a122e573c08e27953531e
Created June 3, 2017 00:09
Convert all lines in a csv to lowercase
cat file.csv | awk '{print tolower($0)}' > file_lowercase.csv
@cdolek
cdolek / gist:63ddb3711264ad602368baaa306906a0
Created June 2, 2017 20:49
Remove first and last character from csv
rev input.csv | cut -c2- | rev | cut -c2-
Or
sed 's/.$//; s/^.//' input.csv
@cdolek
cdolek / gist:2d3f9faa6a98f823579ec8b6c0766a76
Last active June 5, 2017 22:15
Get n rows from a text file
# From 2 to 4
sed '2,4!d' somefile.txt
@cdolek
cdolek / gist:c932ee612bc1967b42ea51ce10f42b83
Created June 2, 2017 18:26
Add string to every line of a CSV file
while IFS= read -r line; do echo "$line,string_I_would_like_to_add,some_other_string"; done < file
@cdolek
cdolek / gist:5670945111115fedb7ae420b4dcd8757
Last active June 2, 2017 20:43
Shell - get nth column of a csv file
# Get 2nd column of a csv file
awk -F "\"*,\"*" '{print $2}' sourceFile.csv > targetFile.csv
# Or
awk -F "," '{print $1}' someOtherSourceFile.csv > new.csv