# Add a comment to line with matching pattern sed -e '/matchme/ s!^!#!' /etc/people # Change a login shell in passwd for user sed -e '/^pfowler:/ s!:/bin/false$!:/bin/bash!' # Replace new lines with a character (;) sed ':a;N;$!ba;s/\n/;/g' # Replace commas with a new line tr , '\n'
# Ignore first line awk '{if (NR != 1) {print $1}}' # Change Input & Output separators awk -F":" -v OFS=',' '{print $1, $2, 9}' <filename> # Sum a column du -ks /home/*/www | awk '{ SUM += $1} END { print SUM/1024 }' # Print last column awk '{print $NF}'
Print 1st few cols, then from col 9 → end. Example below works for ls -la
#!/bin/bash # Provide a text file in first argument awk -F\ ' { printf("%s,%s,%s,%s-%s-%s,", $3, $4, $5, $8, $7, $6) for (i=9; i<=NF; i++) printf("%s ", $i) printf("\n") } ' $1