Benutzer-Werkzeuge

Webseiten-Werkzeuge


commands-text-processing

Sammlung nützlicher Befehle

Text Processing Commands

Manual Pages

search for a string in all files in directory recursively

grep -r "some magic string" .

show non-empty lines not starting with # character of a file

grep -v -e '^#' -e '^$' input.txt

difference between two files, but ignore certain lines such as code comments

diff --ignore-matching-lines='^\s*#' script1.sh script2.sh

Line-Based Text Processing

cut out the second value of whitespace separated values

cat << THISISEOF | cut -w -f2
a1  a2 a3
b1  b2 b3
c1  c2 c3
THISISEOF
## output contains three lines with "a2", "b2" and "c2"

concatenate each line of multiple files, e.g. to create a CSV from files containing the column values

paste -d";" in0.txt in1.txt in2.txt in3.txt > out.csv

sum of numbers of second column of each line

cat << THISISEOF | awk '{s+=$2} END {print s}'
62 83 18
43 86 93
32 75 43
THISISEOF
## result is 244 (83+86+75)

replace empty lines with a constant string

cat << THISISEOF | awk '!NF{$0="XYZ"}1'
some
 
other
THISISEOF
## result contains "XYZ" in the second line

remove duplicate lines

awk '!a[$0]++' input_file.txt

Misc

awk -v min=10 -v max=100 'BEGIN{srand(); print int(min+rand()*(max-min+1))}'

decode HEX to ASCII

echo 54657374696e672031203220330 | xxd -r -p
Cookies helfen bei der Bereitstellung von Inhalten. Durch die Nutzung dieser Seiten erklären Sie sich damit einverstanden, dass Cookies auf Ihrem Rechner gespeichert werden. Weitere Information
commands-text-processing.txt · Zuletzt geändert: 2021/01/23 07:19 von alex