PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > prefix string in awk's output
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

prefix string in awk's output

Réponse
 
LinkBack Outils de la discussion
Vieux 10/12/2006, 10h48   #1
key9
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut prefix string in awk's output

Hi all

$pfx="prefix"
$export $pfx
$seq 1 10 | awk '{printf $pfx ; print $1}'

I want the output as
prefix1
prefix2
prefix3
....


but it don't work ,how to solve?
thank you very much
your key9


  Réponse avec citation
Vieux 10/12/2006, 11h01   #2
Stephan Grein
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: prefix string in awk's output

key9 wrote:
> Hi all
>

Hi!
> $pfx="prefix"
> $export $pfx
> $seq 1 10 | awk '{printf $pfx ; print $1}'
>
> I want the output as
> prefix1
> prefix2
> prefix3
> ...
>

Okay.
>
> but it don't work ,how to solve?
> thank you very much
> your key9
>
>

For instance:

export pfx=prefix

seq 1 10 | awk ' { printf "%s%d\n", $pfx, $1 } '

echo | awk ' { for (i=0; i<10;i++) { printf "%s%d\n", $pfx, i; } }'

HTH,
--
Stephan Grein, <stephan at stephan minus rockt dot de>
https://stephan-rockt.de
GnuPG-Key-ID: 0xF8C275D4
FingerPrint: 5B6F 134A 189B A24D 342B 0961 8D4B 0230 F8C2 75D4
  Réponse avec citation
Vieux 10/12/2006, 11h04   #3
key9
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: prefix string in awk's output


> export pfx=prefix
>
> seq 1 10 | awk ' { printf "%s%d\n", $pfx, $1 } '
>
> echo | awk ' { for (i=0; i<10;i++) { printf "%s%d\n", $pfx, i; } }'
>

no chance :-(
$export pfx=prefix
$
$seq 1 10 | awk ' { printf "%s%d\n", $pfx, $1 } '
11
22
33
44
55
66
77
88
99
1010
$



  Réponse avec citation
Vieux 10/12/2006, 11h16   #4
Stephan Grein
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: prefix string in awk's output

key9 wrote:
>> export pfx=prefix
>>
>> seq 1 10 | awk ' { printf "%s%d\n", $pfx, $1 } '
>>
>> echo | awk ' { for (i=0; i<10;i++) { printf "%s%d\n", $pfx, i; } }'
>>

> no chance :-(
> $export pfx=prefix
> $
> $seq 1 10 | awk ' { printf "%s%d\n", $pfx, $1 } '
> 11
> 22
> 33
> 44
> 55
> 66
> 77
> 88
> 99
> 1010
> $
>

Oh boy. What shell do you use?
seq 1 10 | awk ' { printf "%s%d\n", "prefix", $1 } '

works _flawless_ on:

stephan@unimatrix ~ $ bash --version
GNU bash, version 3.1.17(1)-release (i686-pc-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.

stephan@unimatrix ~ $ seq 1 10 | awk ' { printf "%s%d\n", "prefix", $1 } '
prefix1
prefix2
prefix3
prefix4
prefix5
prefix6
prefix7
prefix8
prefix9
prefix10

HTH,
--
Stephan Grein, <stephan at stephan minus rockt dot de>
https://stephan-rockt.de
GnuPG-Key-ID: 0xF8C275D4
FingerPrint: 5B6F 134A 189B A24D 342B 0961 8D4B 0230 F8C2 75D4
  Réponse avec citation
Vieux 10/12/2006, 11h17   #5
key9
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: prefix string in awk's output


> Oh boy. What shell do you use?

$bash --version
GNU bash, version 3.1.17(1)-release (i486-pc-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.


  Réponse avec citation
Vieux 10/12/2006, 11h24   #6
Stephan Grein
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: prefix string in awk's output

key9 wrote:
>> Oh boy. What shell do you use?

> $bash --version
> GNU bash, version 3.1.17(1)-release (i486-pc-linux-gnu)
> Copyright (C) 2005 Free Software Foundation, Inc.
>
>


I see, so what gives you

seq 1 10 | awk ' { printf "%s%d\n", "prefix", $1 } '

?

That's on my side:

stephan@unimatrix ~ $ seq 1 10 | awk ' { printf "%s%d\n", "prefix", $1 } '
prefix1
prefix2
prefix3
prefix4
prefix5
prefix6
prefix7
prefix8
prefix9
prefix10

--
Stephan Grein, <stephan at stephan minus rockt dot de>
https://stephan-rockt.de
GnuPG-Key-ID: 0xF8C275D4
FingerPrint: 5B6F 134A 189B A24D 342B 0961 8D4B 0230 F8C2 75D4
  Réponse avec citation
Vieux 10/12/2006, 11h31   #7
Radoulov, Dimitre
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: prefix string in awk's output


"key9" wrote...
> Hi all
>
> $pfx="prefix"
> $export $pfx
> $seq 1 10 | awk '{printf $pfx ; print $1}'
>
> I want the output as
> prefix1
> prefix2
> prefix3


Do you really need awk?

printf "$pfx%d\n" $(seq 10)

or (if your shell supports it):

printf "$pfx%d\n" {1..10}


And if you really need awk:

seq 10 | awk '$0=p$0' p="$pfx"

or

awk 'BEGIN{for (i=1;i<=10;i++)print "prefix"i}'


Regards
Dimitre





  Réponse avec citation
Vieux 10/12/2006, 11h35   #8
key9
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: prefix string in awk's output


> I see, so what gives you
>
> seq 1 10 | awk ' { printf "%s%d\n", "prefix", $1 } '
>
> ?
>
> That's on my side:
>
> stephan@unimatrix ~ $ seq 1 10 | awk ' { printf "%s%d\n", "prefix", $1 } '
> prefix1
> prefix2
> prefix3
> prefix4
> prefix5
> prefix6
> prefix7
> prefix8
> prefix9
> prefix10


I got that, so far I using
#!/bin/bash
while read line; do
echo $pfx;
echo "${line}";
done

to solve this problem temporarily,instead of awk

I am on google to find out why things goes wrong, may be I turn off some
trait?

btw ,as
"seq 1 10 | awk ' { printf "%s%d\n", "prefix", $1 } '"
works
seq 1 10 | awk '{printf $pfx ; print $1}'
this should also work
becasue they have same output on my machine.


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h43.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,14333 seconds with 16 queries