Linux Text Processing
- awk:
- Remove some columns:
awk '{$6=$8=""; print $0}' file
- Remove some columns:
- cut:
- Display first x characters:
cut -c 1-35 <file>
- Cut the first x characters:
cut -c 1-35 --completement <file>
- Display first x characters:
- grep:
- Treat binary file as text file:
grep -a data fsstatus.log
- Treat binary file as text file:
- sed:
- sed on a string (not a file) using a here string:
sed "s/,/','/g" <<< "A,B,C"
- Extract last section from multiple top outputs:
COLUMNS=1024 top -b -d 1 -n 2 -c | sed -n 'H;/^top/h;\${g;p;}'
- sed on a string (not a file) using a here string:
- sort
- Sort numeric column 3 in CSV file:
sort -t ',' -n -k 3,3 data.csv
- Sort numeric column 3 in CSV file:
Written on October 13, 2020