Some scripting languages like bash require a $ prefix when you need the value stored in a variable. For example, if you declare name='Joe' you'd need echo "$name" to print the value. This may result in using $prefix and other bashisms in awk as well when you are a beginner. To make it a bit worse, awk has the $N syntax for accessing field contents, which could result in false comprehension that all variables need $ prefix to access their values. See also unix.stackexchange: Why does awk print the whole line when I want it to print a variable?.
$ # silently fails, $word becomes $0 because of string to numeric conversion $ awk -v word="cake" '$2==$word' table.txt $ # works when the variable is used correctly $ awk -v word="cake" '$2==word' table.txt blue cake mug shirt -7 $ # here 'field' gets replaced with '2' and hence $2 is printed $ awk -v field=2 '{print $field}' table.txt bread cake banana
As mentioned before, line endings differ from one platform to another. On Windows, it is typically a combination of carriage return and the newline character and referred as dos style line endings. Since GNU awk allows multicharacter RS, it is easy to handle. See stackoverflow: Why does my tool output overwrite itself and how do I fix it? for a detailed discussion and various mitigation methods.
$ # no issue with unix style line ending $ printf 'mat dog\n123 789\n' | awk '{print $2, $1}' dog mat 789 123 $ # dos style line ending causes trouble $ printf 'mat dog\r\n123 789\r\n' | awk '{print $2, $1}' mat 123 $ printf 'mat dog\r\n123 789\r\n' | awk '{sub(/$/, ".")} 1' .at dog .23 789 $ # use \r?\n if you want to handle both unix and dos style with same command $ # note that ORS would still be newline character only $ printf 'mat dog\r\n123 789\r\n' | awk -v RS='\r\n' '{print $2, $1}' dog mat 789 123 $ printf 'mat dog\r\n123 789\r\n' | awk -v RS='\r\n' '{sub(/$/, ".")} 1' mat dog. 123 789.