Variables with *WHITE SPACE*.. 
Author Message
 Variables with *WHITE SPACE*..

EXAMPLE FROM COMMAND LINE
--------------------------------------------------------
$ variable="string 1"
$ echo $variable
string 1
$ echo "field1 field2" | awk '{print $2}'
field 2
$ echo "field1 field2" | awk '{print "'$variable'", $2}'
awk: cmd. line:1: {print "string
awk: cmd. line:1:        ^ unterminated string
--------------------------------------------------------

Argh... how can I get past this? It should print 'string 1 field2'.

I really need AWK to put a variable with white space in front of each
record/line. Plz help if u know a workaround! Thanx in advance.



Mon, 21 Jul 2003 11:48:43 GMT  
 Variables with *WHITE SPACE*..

Quote:

>EXAMPLE FROM COMMAND LINE
>--------------------------------------------------------
>$ variable="string 1"
>$ echo $variable
>string 1
>$ echo "field1 field2" | awk '{print $2}'
>field 2
>$ echo "field1 field2" | awk '{print "'$variable'", $2}'
>awk: cmd. line:1: {print "string
>awk: cmd. line:1:        ^ unterminated string
>--------------------------------------------------------

$ echo "field1 field2" | awk '{print "'"$variable"'", $2}'
or
echo "field1 field2 | awk -v var="$variable" '{print var,$2}'


Mon, 21 Jul 2003 12:23:11 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. white white white people

2. setting RS for records separated by white space

3. Stripping white space from fields?

4. Delete White Space in Strings

5. attribute setting method white space, bug?

6. White space at end of record dissapears (MicroFocus)

7. parsing XML - getting lots of white space

8. Regular Expressions: Match any character including newline and white space

9. Newbie: White space

10. Newbie White Space

11. White Space with Python AX ASP Srcipts

12. parser: how to ignore white spaces best

 

 
Powered by phpBB® Forum Software