Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I was reading this awk script

awk -F"=" '{OFS="=";gsub(",",";",$2)}1'

I want to know what is the function of 1 at the end of it

share|improve this question
add comment

2 Answers 2

up vote 11 down vote accepted

An awk program is a series of condition-action pairs, conditions being outside of curly braces and actions being enclosed in them. A condition is considered false if it evaluates to zero or the empty string, anything else is true (uninitialized variables are zero or empty string, depending on context, so they are false). Either a condition or an action can be implied; braces without a condition (as yours begins) are considered to have a true condition and are always executed if they are hit, and any condition without an action will print the line if and only if the condition is met.

The 1 at the end of your script is a condition (always true) with no action, so it executes the default action for every line, printing the line (which may have been modified by the previous action in braces).

share|improve this answer
add comment

1 means to print every line.

The awk statement is same as writing:

awk -F"=" '{OFS="=";gsub(",",";",$2);print $0;}'
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.