Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

What is the meaning of these three shell commands?

# 1
grep "[a-zA-Z]"

# 2
sort -u

# 3
awk -F"," '{if($4 == "2" && $6 == "UPD-LOC" && $7 == "OUT"){ 
            print $11,$12,$18,$23,$11$12 
           }}' $txnfile_fail | sort | tr ' ' ',' >$TEMP_FOLDER/txnFailOut-$1.txt
share|improve this question

migrated from stackoverflow.com Jun 2 '11 at 3:15

This question came from our site for professional and enthusiast programmers.

closed as not a real question by Nifle, random Aug 19 '11 at 12:28

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers 2

Not sure why this got downmodded to oblivion, but anyway.

grep "[a-zA-Z]"

grep is a search tool, using regular expressions. This specific expression looks for a character range (in brackets) of lowercase (a-z) or uppercase (A-Z). So, it will match a single ASCII letter on input.

NOTE Since this line does not say a file (or a pipe) to read from, it will read from stdin until you end it with a Ctrl-D. Meaning your terminal will appear to hang, even though it's searching.

sort -u

Sort stdin (see note above) then coalesce lines that are next to each other into a single line, meaning list only unique lines

awk -F"," '{if($4 == "2" && $6 == "UPD-LOC" && $7 == "OUT"){ 
            print $11,$12,$18,$23,$11$12 
           }}' $txnfile_fail | sort | tr ' ' ',' >$TEMP_FOLDER/txnFailOut-$1.txt

awk is a useful tool for manipulating text files, somewhere between bash+grep and perl in complexity and headaches. This is using awk's power to read columns,

Run the awk tool on the file named in the variable $txnfile_fail. The -F flag is for field delimiter, so its a comma delimited input file. Check if the 4th field is a 2, if the 6th field is 'UPD-LOC', and the 7th field is 'OUT'. If so, dump out fields 11, 12, 18, 11, 12. Then sort the output, translate spaces to commas, and then dump to the file $TEMP_FOLDER/txnFailOut-$1.txt.

So, it filters a csv file, prints only certain columns, sorts the filtered input and dump to a different file. Oddly its fine with spaces as output separators, then translates the spaces to different characters. You can set the separator in awk with the 'OFS=,' awk statement.

share|improve this answer

The first word of each of the items listed is the command name.

You can use the manuals for each command to get a better idea of what they do. For example man grep brings up the manual for the grep command.

The text listed after the command name are arguments passed to the command, which give it further instructions as to what it should do. You can learn more about the various arguments for each command through the man page. That should help with the first two.

The awk command shown is a bit tricker, but there's a more elaborate user guide available online.

share|improve this answer