Created
July 27, 2018 10:33
-
-
Save electric380v/d89ac23c29571e9cda38267239d2e082 to your computer and use it in GitHub Desktop.
Some useful text manipulation commands (sed, gawk, etc.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# print the number of columns | |
gawk '{print NF}' file | sort -nu | tail -n 1 | |
# Use head -n 1 for lowest column count, tail -n 1 for highest column count. | |
# print columns | |
gawk '{print $0}' file # all columns | |
gawk '{print $4}' file # 4th column | |
gawk -F "," '{print $2}' file # specific separator | |
# split a string with a delimiter into lines | |
echo "string1:string2:string3:string4:string5" | sed s/:/\\n/g | |
# remove first line from a file | |
sed '1d' file.txt > tmpfile; mv tmpfile file.txt # POSIX | |
sed -i 's/original_regex/new_regex/g' file.txt # replace text within a file | |
sed -i.bak '/pattern to match/d' file.txt # remove lines with matched pattern | |
sed -i '1d' file.txt # GNU sed only, creates a temporary file | |
sed 's/.*/&&/g' file.txt > file.enum # duplicate matched pattern | |
paste -d, a.csv b.csv # merge lines of many files |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment