Skip to content

Instantly share code, notes, and snippets.

@garethrees
Created September 20, 2017 08:18
Show Gist options
  • Select an option

  • Save garethrees/6b7c4b81346797f5e72fa51d20ac0dff to your computer and use it in GitHub Desktop.

Select an option

Save garethrees/6b7c4b81346797f5e72fa51d20ac0dff to your computer and use it in GitHub Desktop.
Sed & Awk Examples
# Print column 1
awk '{print $1}' FILE
# Print column 1 and 2, separated by '/'
awk '{print $1 "/" $2}' FILE
# Print line 1 and 5
sed -n -e 1p -e 5p FILE
@garethrees
Copy link
Author

@garethrees
Copy link
Author

Average a list of numbers:

awk '{a+=$1} END{print a/NR}'

https://stackoverflow.com/a/9789898/387558

@garethrees
Copy link
Author

tail -n +2 to show all bit first line of file/stdin

@garethrees
Copy link
Author

@garethrees
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment