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.

On my local system, it appears that the configuration for awk has somehow been changed.

Running the following command:

echo "Hi there" | awk '{print $2}'

On my machine this prints:

Hi there

And on my development server it prints:

there

I am sure that at some point my local machine would behave the same as my server - i.e. it should print only the second word.

How do I reset the awk field separator back to its default (which according to this page is a sequence of spaces)?

share|improve this question
    
Yeah, no... there's... there's no way it could possibly have the former output. Unless it's not awk. –  Ignacio Vazquez-Abrams May 12 '11 at 16:06
    
Apologies. I was actually running this on my local system: echo "Hi there" | awk "{print $2}" Hadn't realised that double quotes and single quotes were used differently. –  Alex Spurling May 12 '11 at 16:14
    
Indeed. Double quotes allow variable substitution, which would cause $2 to collapse to nothing, printing the whole line. –  Ignacio Vazquez-Abrams May 12 '11 at 16:15
1  
You might have done this: echo Hi there | awk '{print $2}' –  ceving May 12 '11 at 16:16
    
/ Ignacio: I hope one of you will post an answer regarding double quotes - then Alex can mark it as accepted. –  RedGrittyBrick May 12 '11 at 19:31

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.