|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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! |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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? |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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. |
|
![]() |
| Outils de la discussion | |
|
|