Printing multiple word strings with awk/printf in bash script

From: Giulia Paramour (giulia_paramour_at_postmaster.co.uk)
Date: 11/18/03


Date: Tue, 18 Nov 2003 14:24:49 +0000


Hi,

Having a bit of a newbie problem with writing a bash script. The snippet
below embodies the essence of the thing. User inputs a multiple word
string from the command line. I then want to use awk to insert this
string into another file, but printf has problems with strings
containing spaces. Is there some fancy way of quoting this? What to do?
Sorry if this is obvious.

Best wishes,
Giulia

----------------------------------------------------------------------

#!/bin/bash

read keyword

# user inputs : hello world

echo $keyword

# hello world

awk '{printf "%s \n","'$keyword'" >> "file"}' input

# awk: cmd. line:1: {printf "%s \n","hello
# awk: cmd. line:1: ^ unterminated string

-- 
====================================
  Giulia Paramour
  giulia_paramour@postmaster.co.uk
====================================


Relevant Pages