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 > awk command
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

awk command

Réponse
 
LinkBack Outils de la discussion
Vieux 26/07/2007, 03h28   #1
skarlhet@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut awk command

Hello everyone. I was wondering if someone could me.

I have a file hello.txt which contains the following:

field|2|value
field|2|document
field|3|exclude
field|2|include

I want to write into a file only those records which have value of 2
in the second column

I used this command
$ awk -F\| '$2=="2"' hello.txt > out_hello.txt

but the output looks like this
field|2|value field|2|document field|2|include

I want them to be in this format
field|2|value
field|2|document
field|2|include


Thanks a lot!

  Réponse avec citation
Vieux 26/07/2007, 03h55   #2
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: awk command

On 2007-07-26, skarlhet@gmail.com wrote:
> Hello everyone. I was wondering if someone could me.
>
> I have a file hello.txt which contains the following:
>
> field|2|value
> field|2|document
> field|3|exclude
> field|2|include
>
> I want to write into a file only those records which have value of 2
> in the second column
>
> I used this command
> $ awk -F\| '$2=="2"' hello.txt > out_hello.txt
>
> but the output looks like this
> field|2|value field|2|document field|2|include
>
> I want them to be in this format
> field|2|value
> field|2|document
> field|2|include


They are (if you posted the command you actually ran).

How are you determining the format of the output file? Did you use:

cat out_hello.txt

Did you try running the command without redirecting the output?

If not, try either of those.

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 26/07/2007, 05h01   #3
skarlhet@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: awk command

yeah sorry. you are right. obviously this is not my actual file. but
the problem may be that in my actual file, one line contains 224
characters. the input file looks okay but when i process it with the
awk command, the format of the output is no longer the same as the
input. do you have ideas regarding this?

  Réponse avec citation
Vieux 26/07/2007, 05h12   #4
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: awk command

On 2007-07-26, skarlhet@gmail.com wrote:
> yeah sorry. you are right. obviously this is not my actual file. but
> the problem may be that in my actual file, one line contains 224
> characters. the input file looks okay but when i process it with the
> awk command, the format of the output is no longer the same as the
> input. do you have ideas regarding this?


Regarding what?

You are posting to Usenet, not a web forum. Please include enough
context from the post you are replying to so that we know what you
are talking about.

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 26/07/2007, 06h04   #5
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: awk command

On Wed, 25 Jul 2007 19:28:00 -0700, skarlhet@gmail.com
<skarlhet@gmail.com> wrote:
>
>
> Hello everyone. I was wondering if someone could me.
>
> I have a file hello.txt which contains the following:
>
> field|2|value
> field|2|document
> field|3|exclude
> field|2|include
>
> I want to write into a file only those records which have value of 2
> in the second column
>
> I used this command
> $ awk -F\| '$2=="2"' hello.txt > out_hello.txt
>
> but the output looks like this
> field|2|value field|2|document field|2|include
>
> I want them to be in this format
> field|2|value
> field|2|document
> field|2|include
>
> Thanks a lot!
>

Maybe the lines in the file end with \r instead of \n.


--
We are the people our parents warned us about.
  Réponse avec citation
Vieux 28/07/2007, 17h11   #6
Robert Bonomi
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: awk command

In article <1185422512.363936.226600@x35g2000prf.googlegroups .com>,
<skarlhet@gmail.com> wrote:
>yeah sorry. you are right. obviously this is not my actual file. but
>the problem may be that in my actual file, one line contains 224
>characters. the input file looks okay but when i process it with the
>awk command, the format of the output is no longer the same as the
>input. do you have ideas regarding this?
>


Yes, I have a very good idea.

You're doing something wrong.

Find it.

Fix it,

And things _will_ work.

This authoritatively correct response to your question contains exactly as
much usable information as you provided in your description.

Note: to get ful answers you have to show _exactly_ the stuff actually
causing the problem. If you can't show the 'real' data, then you have
to 'make up' data that also demonstrates the problem.

You have to show an _actual_ example from which others can reproduce
the behavior you're seeing.

Saying: "When I runs a routine approximately like this, on data that is
more-or-less like this, I get this 'incorrect' behavior." is simply
wasting your time, _and_ ours.

You *are* free to waste your time, just don't expect anybody to take the
time to try to read your mind, figure out what you were _actually_ doing
that give the reported results, and tell you how to fix it.


  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 12h57.


Édité par : vBulletin® version 3.7.3
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,15457 seconds with 14 queries