onlyforbopi
3/10/2017 - 10:43 AM

AWK TEXT CONVERSION AND CLEANING

AWK TEXT CONVERSION AND CLEANING

Convert Windows/DOS newlines (CRLF) to Unix newlines (LF) from Unix					awk '{ sub(/\r$/,""); print }'						
Convert Unix newlines (LF) to Windows/DOS newlines (CRLF) from Unix					awk '{ sub(/$/,"\r"); print }'						
Convert Unix newlines (LF) to Windows/DOS newlines (CRLF) from Windows/DOS.					awk 1						
Convert Windows/DOS newlines (CRLF) to Unix newlines (LF) from Windows/DOS					gawk -v BINMODE="w" '1'						
Convert Windows/DOS newlines (CRLF) to Unix newlines (LF) from Windows/DOS					tr -d \r						
Delete leading whitespace (spaces and tabs) from the beginning of each line (ltrim).					awk '{ sub(/^[ \t]+/, ""); print }'						
Delete trailing whitespace (spaces and tabs) from the end of each line (rtrim).					awk '{ sub(/[ \t]+$/, ""); print }'						
Delete both leading and trailing whitespaces from each line (trim).					awk '{ gsub(/^[ \t]+|[ \t]+$/, ""); print }'						
Delete both leading and trailing whitespaces from each line (trim).					awk '{ $1=$1; print }'						
Insert 5 blank spaces at beginning of each line.					awk '{ sub(/^/, "     "); print }'						
Align all text flush right on a 79-column width.					awk '{ printf "%79s\n", $0 }' 						
Center all text on a 79-character width.					awk '{ l=length(); s=int((79-l)/2); printf "%"(s+l)"s\n", $0 }'