Skip to content

Instantly share code, notes, and snippets.

@ngzhian
Last active April 16, 2017 11:46
Show Gist options
  • Save ngzhian/d6fffc4a2102aa2e48a293a0b329e187 to your computer and use it in GitHub Desktop.
Save ngzhian/d6fffc4a2102aa2e48a293a0b329e187 to your computer and use it in GitHub Desktop.
bash snippets
# read line by line from file
while read p; do
echo $p
done <file
# change first letter from upper to lower
q="$(tr '[:upper:]' '[:lower:]' <<< ${p:0:1})${p:1}"
# sed variable substitution
sed "s/$var/r_str/g" file_name >new_file
# take note of the double quote, this is a common pattern in bash, double quote allows sub, single doesn't
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment