f



AWK bug? Changing one field affects output delimiter

Hi, 

This seems a bug to me because I think changing one field should not affect
the input/output field separators. But my current awk does:

My test file:

$ cat $tf.tst | tee /dev/tty | od -t x1
Ssssss  Ffff    777     2222    fssssss@somewhere.org
0000000 53 73 73 73 73 73 09 46 66 66 66 09 37 37 37 09
0000020 32 32 32 32 09 66 73 73 73 73 73 73 40 73 6f 6d
0000040 65 77 68 65 72 65 2e 6f 72 67 20 0a

First test:

$ cat $tf.tst | awk -F'\t' '{uid=$5; printf NR "\t" uid "\t"; print}' | od -t x1
0000000 31 09 66 73 73 73 73 73 73 40 73 6f 6d 65 77 68
0000020 65 72 65 2e 6f 72 67 20 09 53 73 73 73 73 73 09
0000040 46 66 66 66 09 37 37 37 09 32 32 32 32 09 66 73
                    ^^          ^^             ^^
0000060 73 73 73 73 73 40 73 6f 6d 65 77 68 65 72 65 2e
0000100 6f 72 67 20 0a
0000105

Still fine, but watch this:

$ cat $tf.tst | awk -F'\t' '{gsub(/ /, "", $5); uid=$5; printf NR "\t" uid "\t"; print}' | od -t x1
0000000 31 09 66 73 73 73 73 73 73 40 73 6f 6d 65 77 68
0000020 65 72 65 2e 6f 72 67 09 53 73 73 73 73 73 20 46
0000040 66 66 66 20 37 37 37 20 32 32 32 32 20 66 73 73
                 ^^          ^^             ^^
0000060 73 73 73 73 40 73 6f 6d 65 77 68 65 72 65 2e 6f
0000100 72 67 0a
0000103

Notice the output field separators have been changed?

My awk:

$ awk --version
GNU Awk 3.1.5

thanks

-- 
Tong (remove underscore(s) to reply)
  http://xpt.sf.net/techdocs/
  http://xpt.sf.net/tools/

-- 
Posted via a free Usenet account from http://www.teranews.com

0
4/4/2007 12:45:53 AM
comp.unix.shell 15484 articles. 2 followers. Post Follow

1 Replies
291 Views

Similar Articles

[PageSpeed] 28

On 04 Apr 2007 00:45:53 GMT, * Tong * 
  <sun_tong_001@users.sourceforge.net> wrote:
>
>
> Hi, 
>
> This seems a bug to me because I think changing one field should not affect
> the input/output field separators. But my current awk does:
>
This is not a bug.  Changing a field or changing the value of $0 or NF 
causes the record to be rebuilt.  See the section under "Fields" in the 
awk man page, or info gawk "Changing Fields".  
If you want the output fields to be separated by tabs, you can set 
OFS="\t" or OFS=FS.

-- 
Captain Penny's Law:
	You can fool all of the people some of the
	time, and some of the people all of the
	time, but you can't fool mom.
0
Bill
4/4/2007 5:19:47 AM
Reply:

Similar Artilces:

Unix Need Help with auto incrementing a field between delimiter. Awk?
I need to know if there is a simple way to auto increment the 2nd delimited field with padding of 9 digits with leading zeros. Example Input File: ST*271*111111111~BHT*0022* ST*271*222222222~BHT*0022* ST*271*333333333~BHT*0022* ST*271*444444444~BHT*0022* ST*271*555555555~BHT*0022* ST*271*666666666~BHT*0022* What I need: ST*271*000000001~BHT*0022* ST*271*000000002~BHT*0022* ST*271*000000003~BHT*0022* ST*271*000000004~BHT*0022* ST*271*000000005~BHT*0022* ST*271*000000006~BHT*0022* This is what I currently have, but it replaces all instances in the file with the value of $cnt. cnt=000000001...

Unix Need Help with auto incrementing a field between delimiter. Awk? #2
I need to know if there is a simple way to auto increment the 2nd delimited field with padding of 9 digits with leading zeros. Example Input File: ST*271*111111111~BHT*0022* ST*271*222222222~BHT*0022* ST*271*333333333~BHT*0022* ST*271*444444444~BHT*0022* ST*271*555555555~BHT*0022* ST*271*666666666~BHT*0022* What I need: ST*271*000000001~BHT*0022* ST*271*000000002~BHT*0022* ST*271*000000003~BHT*0022* ST*271*000000004~BHT*0022* ST*271*000000005~BHT*0022* ST*271*000000006~BHT*0022* This is what I currently have, but it replaces all instances in the file with the value of $cnt. cnt=000000001...

DDS -- Change Field From Input/Output to Output Only
Sometimes when I do F10 to pull fields from a file to put on a display, I accidently use option #4 (Input/Output) instead of #3 (Output Only). The only way I know how to fix this is to exit out of the DDS, use SEU option #2 to update, change the "B" to an "O" and then go back to creating the display. Is there a way to fix this without backing out of SEU option #17? TIA. On the SDA work screen the I/O fields are represented by I, O or B for character and 3, 6 or 9 for numeric. Simply change the first character to the type of field you want. For example if the field is shown as IIIIIIIIIIIIII change it to BIIIIIIIIIIIII and press enter. It will convert to BBBBBBBBB. Denny On Tue, 10 Jul 2007 21:05:48 -0000, Chipper Miller <chipper.miller@gmail.com> wrote: >Sometimes when I do F10 to pull fields from a file to put on a >display, I accidently use option #4 (Input/Output) instead of #3 >(Output Only). The only way I know how to fix this is to exit out of >the DDS, use SEU option #2 to update, change the "B" to an "O" and >then go back to creating the display. Is there a way to fix this >without backing out of SEU option #17? TIA. Perfect! Thanks, Denny! (As an aside, I've done the same thing with +99999 instead of +66666 before.) ...

web hosting, shell provider, unix shells, bnc shell, ircd provider, shell hosting, bnc shells, irc shells, ircd shells, unix shell account, irc shell, irc, eggdrop shell, irc vps, irc shell, linux vps
http://www.hostrazor.net/ web hosting, shell provider, unix shells, bnc shell, ircd provider, shell hosting, bnc shells, irc shells, ircd shells, unix shell account, irc shell, irc, eggdrop shell, irc vps, irc shell, linux vps -- questo articolo e` stato inviato via web dal servizio gratuito http://www.newsland.it/news segnala gli abusi ad abuse@newsland.it ...

How to let output from one awk program as input to another awk program?
Dear All, I am wondering how to make output from one awk program as input data to feed another awk program. For example, I have a.awk, b.awk. awk -f a.awk mydata.dat will output to the standard out. I hope to use these generated data as input data to feed b.awk. I hate to save the result from "awk -f a.awk mydata.dat" as a temporary tile "temp.dat" and then awk -f b.awk temp.dat Many thanks. Tom wrote: > I am wondering how to make output from one awk program as input data to > feed another awk program. For example, I have a.awk, b.awk. > > awk -f...

Hardware Cosim one wrong output and one correct output
Hi all, I have designed a DDC component with 2 outputs representing the I path and the Q path outputs. Simulation in Simulink works fine. However when I did hardware cosim, the Q path hardware cosim output is fine but the I path hardware cosim output seem to have incur noise as that output seems to output a waveform that is off set by a magnitude of 2000 in the timescope domain. I would appreciate if some one has an answer to this. I do suspect it could be possible due to a limit on the maximum hardware oversampling of my FIR Compiler to not be more than 5 as I saw before on the manual that...

Separating one field into two fields based on a character in the field
I know there has to be a way to do this, but I've gone brain dead. The scenario..a varchar field in a table contains a date range (i.e. June 1, 2004 - June 15, 2004 or September 1, 2004 - September 30, 2004 or...). The users have decided thats a bad way to do this (!) so they want to split that field into two new fields. Everything before the space/dash ( -) goes into a 'FromDate' field, everything after the dash/space goes into the 'ToDate' field. I've played around with STRING commands, but haven't stumbled on it yet. Any help at all would be appreciated! DTS? Try this..... CREATE TABLE Test ( [startdate-enddate] varchar(100) ) insert into Test VALUES ('June 1,2004 - June 15, 2004') insert into Test VALUES ('September 1, 2004 - September 30') ALTER TABLE Test ADD startdate varchar(100),enddate varchar(100) GO UPDATE Test SET startdate = SUBSTRING([startdate-enddate],0,CHARINDEX('-',[startdate-enddate],0)), enddate = substring([startdate-enddate],charindex('-',[startdate-enddate],0)+1,LEN([startdate-enddate])-CHARINDEX('-',[startdate-enddate],0)) FROM Test SELECT * FROM Test ALTER TABLE Test DROP COLUMN [startdate-enddate] GO SELECT * FROM Test DROP TABLE Test "steven virnig" <pezguy@mn.rr.com> wrote in message news:<sHjdd.20301$mR.920@twister.rdc-kc.rr.com>... > I know there has to be a way to do this, but I've gone brain dead. The > scenario..a varcha...

QRY : Changing a CHAR field to a DEC one
Hi there I have two files which i am joining in a query. Two fields have the same name but it won't do the join as one is a CHAR field and the other a DEC. How can i convert one of them to make the join? Is it possible within QRY itself? On Mar 26, 8:37=A0am, Admin Rookie <paul.mcfad...@gmail.com> wrote: > Hi there > > I have two files which i am joining in a query. > Two fields have the same name but it won't do the join as one is a > CHAR field and the other a DEC. > How can i convert one of them to make the join? > Is it possible within QRY itself? Define a new field, look at using digits keyword. On Mar 26, 1:13=A0pm, iseriesflorida <iseriesflor...@yahoo.com> wrote: > On Mar 26, 8:37=A0am, Admin Rookie <paul.mcfad...@gmail.com> wrote: > > > Hi there > > > I have two files which i am joining in a query. > > Two fields have the same name but it won't do the join as one is a > > CHAR field and the other a DEC. > > How can i convert one of them to make the join? > > Is it possible within QRY itself? > > Define a new field, look at using digits keyword. Unfortunately i can't define a new field as it's something thats updated daily and cant be changed. I ahve to leave the data untouched. il 26/03/2009 16.17, Scrive Admin Rookie 43182640: > On Mar 26, 1:13 pm, iseriesflorida <iseriesflor...@yahoo.com> wrote: >> On Mar 26, 8:37 am, Admin Rookie <pa...

Capture unix command shell output to a buffer
Hello All, I searched for this for long time but no luck. Basically, I need to capture the shell command output to a buffer not to a file. For example, I will have buffer, char output[100]; and I want to capture the result of 'ls' command in that buffer. I am doing this on read only file system so I don't have luxury to create a file. Is this possible? .. if so, then can some tell me how? Any help is much appreciated. In article <1103754826.982519.144770@c13g2000cwb.googlegroups.com>, "New User" <webcontacts00@yahoo.com> wrote: > Hello All, > >...

multiply shell variables in one awk statement
Hi I wish to have multiply shell variable in one awk statement eg, without using shell variable awk 'NR>2 && NR<=10' $1> new_$1 $1 is a shell variable which is the input_data filename, new_$1 is the output, this above statment works but , i have trouble getting the following echo $lineOne #lineOne is 2 echo $lineTwo #lineTwo is 10 case 1 ) awk 'NR>'$lineOne' && NR<='$lineTwo' ' $1> new_$1 it would not work. case 2) awk 'NR>awkvar && NR<=awkvar2' awkvar=$lineOne awkvar2=$lineTwo $1 > new_$1 it would not work. case 3) awk -v awkvar=$lineOne awkvar2=$lineTwo 'NR>awkvar && NR<=awkvar2' $1 > new_$1 it would not work. I have using ksh here.. Please help me out with this, since all 3 cases i tried are not working. Thanks noelloen wrote: > Hi > > I wish to have multiply shell variable in one awk statement > > eg, > without using shell variable > awk 'NR>2 && NR<=10' $1> new_$1 > > $1 is a shell variable which is the input_data filename, new_$1 is the > output, this above statment works but , i have trouble getting the > following > > > echo $lineOne #lineOne is 2 > echo $lineTwo #lineTwo is 10 > > case 1 ) > awk 'NR>'$lineOne' && NR<='$lineTwo' ' $1> new_$1 > > it would not work. > > case 2) > awk 'NR>awk...

windows one liner to output unix line feed
I have a simple one liner running on Windows that does a substitution. However, with the -p option, the line endings are coming out \r\n, and I need them to be just \n. I searched for the -l option, but couldn't find how to specify unix line breaks on output Here's the code: perl -pi.bak -e "s|foo|bar|g" myfile.txt thanks At 2009-08-19 01:28PM, "boman" wrote: > I have a simple one liner running on Windows that does a substitution. > However, with the -p option, the line endings are coming out \r\n, and > I need them to be just \n. > > perl ...

Conditional value list choice affecting more than one field
Hi I am in the process of setting up a tracker system for my company. As part of the process users want to be able to create requests from different departments in one portal as part of an individual order. I hope to be able to do this by using a conditional value list whereby the choice of first value list will detemine department choice thereafter affecting the choices of other value lists in a portal entry. Each portal entry will have a department value list which will upon selection of a the dept determine product type, labour values, and one or two other specifications unique to taht dep...

Assigning a field variable in awk program to a shell variable
hi myself a newbie to unix shell scripting and stuff.. i want to assign a field variable in an awk program to a shell variable. like for eg if shell_var is one of a shell variable then i want to assign the line numbers returned by the grep command with -n option to a shell variable. the code that i've tried is this grep -n string filename | awk -F : '{shell_var = $1}' it doesn't work please help.. deeplights@gmail.com wrote: > hi > myself a newbie to unix shell scripting and stuff.. > i want to assign a field variable in an awk program to a shell > variable. &g...

3x3 Array of int, changing one value affects others
ruby-1.9.2-head > a = Array.new(3, Array.new(3, 0)) => [[0, 0, 0], [0, 0, 0], [0, 0, 0]] ruby-1.9.2-head > a[0][2] = 1 => 1 ruby-1.9.2-head > a => [[0, 0, 1], [0, 0, 1], [0, 0, 1]] If the values aren't all 0s, a[0][2] behaves correctly. Am I doing something wrong? Thanks. -- Posted via http://www.ruby-forum.com/. On Tue, Sep 28, 2010 at 10:47 AM, Williams Williams <shaolinog@hotmail.com> wrote: > ruby-1.9.2-head > a =3D Array.new(3, Array.new(3, 0)) > =A0=3D> [[0, 0, 0], [0, 0, 0], [0, 0, 0]] > ruby-1.9.2-head > a[0][2] =3D 1 >...

awk operations using various fields in consecutive output lines
I often extract alphanumerical data fields from a large number of text-format files using grep, sed, head, tail and other utilities, but cannot figure out a general and simple (inline) awk procedure to operate on selected fields from selected output lines. For example, if my output is composed of 2 data lines per each processed file, what is the simplest awk expression to print the ratio of the 7th field in the second (or even) line to the 3rd field in the 1st (or odd) field? What if the output were 3 lines per each processed file? I realize a counter should work, but it's all I think I know, and my knowledge of awk is too rusty and could not make it work in practice... Thanks for any general suggestions and an example. --Tony In article <28410e75-a65c-425b-9ce6-d809fe6b4b0b@googlegroups.com>, TonyG <tgozdz@gmail.com> wrote: >I often extract alphanumerical data fields from a large number of text-format >files using grep, sed, head, tail and other utilities, but cannot figure out a >general and simple (inline) awk procedure to operate on selected fields from >selected output lines. > >For example, if my output is composed of 2 data lines per each processed file, >what is the simplest awk expression to print the ratio of the 7th field in the >second (or even) line to the 3rd field in the 1st (or odd) field? > >What if the output were 3 lines per each processed file? > >I realize a count...

Change all grouped field colors based on one groups value.
Here's what I have, In a purchase order database I created, when the order is placed, the order is set to a Value List STATUS field of "Pending". Now when the order gets updated I change the Value List field STATUS to "Shipped". I then created another layout which lists, in a horizontal line, the Purchase Order #, Customer Name, Status, etc. I used conditional formatting to change the the background color in the STATUS field to gray, when the STATUS is switched to "Shipped". Is there anyway to link all the other fields in the horizontal line, and get them to...

File output, change decimal delimiter vom dot to comma
Hi, I want to write scalars to a ascii file and use fprintf for that purpose. In Germany, we habe the comma as decimal delimiter, thus 1/2 = 0,5 and not 0.5. I want to write this to the file. What is the fastest method? I know that I could to a string-search-and-replace-method but this is not elegant. Do you have some hints for me? Thanks Martin In article <47ea0e6e$0$4863$9b4e6d93@newsspool4.arcor-online.net>, Martin Bretschneider <spam@bretschneidernet.de> wrote: >I want to write scalars to a ascii file and use fprintf for that purpose. >In Ge...

Merge/Apply bug number related changes from one branch to another?
All, 1. Developer check in ten files related to a bug number into Dev branch, e.g. bug #123. 2. How can I identify that ten files anytime? Is it based on the comment that developer made when check in? How else can I do it? 3. How can I apply those ten files very precisely from Dev branch to Trunk then to another branch? 4. Can I automate these processes? Please email me directly at barry@goodconsultants.com Thank you in advance. Barry In comp.software.config-mgmt Barry <barry@goodconsultants.com> wrote: > 1. Developer check in ten files related to a bug number...

Changing one field in an updateable query to a new value on a form--without querying
HI: I have a situation where I wish to enter a value in an unbound field on a form and then change the same field in each record on the form so that it reflects the value entered. THe form is suppored by an updatable query (linked to a table). I would rather not use a query approach because it will result in a need for a new form and will create its own complications (although this could be done) I would like to make the change so that it reflects immediately on the form in each record. I am working with macros to accomplish this, and am having a few problems when i get to the end of the table (somehow I am running off the end). Can anyone suggest an easy, non query, method to accomplish this? Regards John Baker -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 If I understand you correctly, you can probably use the Control's AfterUpdate event procedure to set the DefaultValue to whatever the user entered. E.g.: Private Sub MyControl_AfterUpdate() Me!MyControl.DefaultValue = Me!MyControl.Value End Sub HTH, MGFoster:::mgf00 <at> earthlink <decimal-point> net Oakland, CA (USA) -----BEGIN PGP SIGNATURE----- Version: PGP for Personal Privacy 5.0 Charset: noconv iQA/AwUBP/eBvoechKqOuFEgEQIAxgCfU+uMNAizjMNnEGaQ0/nVrcQ/AYUAoNuy xpwLljpIFdSHJKOiqZIC+/Dc =BF9A -----END PGP SIGNATURE----- John Baker wrote: > HI: > > I have a situation where I wish to enter a value in an unbound field on a form and then > change the same field in each recor...

Changing driver for one user changes it for all.
This is so odd to me. I'm googling for references but have had no luck so far. At one company, we have about a dozen people (on Windows XP) using the same Xerox printer. Everyone accesses the printer as a local printer on an IP port. We downloaded a new driver but wanted to roll it out carefully. I installed it on the admin machine by entering the Printer Properties, Advanced tab, New Driver and made sure that the new driver was selected in the "Driver" drop down. It turns out that changing the driver in this drop down changes it for everyone!! It wiped out saved settings too. Question 1: Is this correct behaviour? Are these drivers associated with the physical printer in some way? Question 2: Is it possible to have two users with different drivers? I just tried the same thing on a different network and this did not happen. Is this a Xerox thing? I am not at the company where this happened right now so I can't experiment. Thanks for your time. ..wk. ...

Changing Text Field to ported field
I did a search, and maybe I'm looking things up using the wrong criteria. I apologize if this has been discussed before, and if it has, please let me know where to find it. Thanks. FMPro V6.04 Windows XP Our users are currently entering in all SW code associated with a problem into a text field, using paragraph returns or comma's as delimiters. To make metric gathering more useful, I created a child database to collect the SW mods individually (with all the details that go with them), and have created portal on my main database to this child database so that they can enter in the ...

Changing drop-down field to text field.
I am working on creating an editable grid (for use in adding, deleting, and editing rows back to an Oracle database). I have a JSP that posts back to a servlet, which in turns posts to a WebLogic SFSB and, from there, to the database. On the front end, all cells appear as text fields. However, for certain cells, when the user clicks on the cell, the text field turns into a drop-down field (i.e. Select object), defaulting to the value in the text field (unless the field is blank, in which case the drop-down defaults to the first entry in the drop-down). Once the user has selected a new en...

Separate one field into two fields
Hi, I have an ID text field that is composed of two alphabetical letters and the rest are numbers. This field is also a primary key. In this same table, I want to separate this field into two fields. Then make these two new fields primary keys. The first just contains the two alphabetical letters. The second contains the numerical digits. Is there a way to do this without losing current data? Thanks, Tony On 17 Feb 2006 09:08:07 -0800, Tony wrote: > Hi, > > I have an ID text field that is composed of two alphabetical letters > and the rest are numbers. This field is also a primary key. In this > same table, I want to separate this field into two fields. Then make > these two new fields primary keys. The first just contains the two > alphabetical letters. The second contains the numerical digits. Is > there a way to do this without losing current data? > > Thanks, > > Tony Add 2 new fields to your table, [LetterPortion] and [NumberPortion] as Text datatypes. You can run an update query after you added the two new fields to the table. Update YourTable Set YourTable.LetterPortion = Left([TextField]),2), YourTable.NumberPortion = Mid([TextField],3); Change the field names however you want. Both the letter and number portions are still Text datatype and you still have your original ID field. -- Fred Please respond only to this newsgroup. I do not reply to personal e-mail ...

More than one element of list changing when only one should be
Hello. This program is clunky, I know; I'm not a programmer, but I need to use this program, so I'm writing it. The problem: I have a cursor following the mouse that shows frequency ratios of potential notes in relation to 1/1 (something like Middle C). At any time, the user may hit "t" to move 1/1 to wherever the cursor is. There is also the option to use many regions, so that some of the notes in the score, in region 0, for instance, can have 1/1 as their base, and others, in region 1 for instance, could have perhaps 3/2 as their base. The program starts out with 2 existi...

Web resources about - AWK bug? Changing one field affects output delimiter - comp.unix.shell

Delimiter - Wikipedia, the free encyclopedia
An example of a delimiter is the comma character, which acts as a field delimiter in a sequence of comma-separated values . Delimiters represent ...

Asus - Delimiter
[ad] Ever wondered what technology underpins Watson, the artificial intelligence system that IBM built to conquer the Jeopardy quiz show? Click ...


NZ brings FTTP costs down to FTTN levels - Delimiter
439 points and 99 comments so far on reddit

End of the dot com winter: How Australia's tech startup scene bloomed again - Delimiter 2.0 End of the ...
The long winter after the failure of the dot com boom a decade ago is finally over: Australia's startup spring is here, and its energy is infectious. ...

Joe Hockey - Delimiter
[ad] Ever wondered what technology underpins Watson, the artificial intelligence system that IBM built to conquer the Jeopardy quiz show? Click ...

At&t - Delimiter
news Shadow Communications Minister Malcolm Turnbull has intensified the Coalition’s focus on fibre to the node as an alternative to the fibre ...

External Contributor - Delimiter
[ad] Ever wondered what technology underpins Watson, the artificial intelligence system that IBM built to conquer the Jeopardy quiz show? Click ...

Analysis - Delimiter
[ad] Ever wondered what technology underpins Watson, the artificial intelligence system that IBM built to conquer the Jeopardy quiz show? Click ...

Abc - Delimiter
[ad] Ever wondered what technology underpins Watson, the artificial intelligence system that IBM built to conquer the Jeopardy quiz show? Click ...

Resources last updated: 3/29/2016 1:55:52 AM