Sponsored Content
Top Forums Shell Programming and Scripting awk how to replace specific field with new value Post 302511461 by freegnu on Wednesday 6th of April 2011 09:04:10 PM
Old 04-06-2011
Need more info

Is the value you want to replace always the second value in the second row? Or is it the only nonzero value in the file? Do the files only have 3 rows?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to replace particular field

i have bad data for instance, the use of capital letters in the middle of the word. I identified the errors, made a list and put it in a file error_correction.txt Incorrect,Correct VeNOM,Venom nos,NOS . . . My data file looks like this: vgr,bugatti veron,,3.5,Venom,6,.......,....... (14 Replies)
Discussion started by: VGR
14 Replies

2. Shell Programming and Scripting

Awk to replace a field

Hi I am using awk to replace the 4th feild of the input line. My code is below: REP_LINE=$(echo $Line | awk -v var=$REPL_DT '{$4=var; print}') It does replaces but all words/phrases after the 4th feild are erased. Is there a way to modify the 4th feild of the input line and to have all... (7 Replies)
Discussion started by: sugan
7 Replies

3. Shell Programming and Scripting

Replace specific field on specific line sed or awk

I'm trying to update a text file via sed/awk, after a lot of searching I still can't find a code snippet that I can get to work. Brief overview: I have user input a line to a variable, I then find a specific value in this line 10th field in this case. After asking for new input and doing some... (14 Replies)
Discussion started by: crownedzero
14 Replies

4. Shell Programming and Scripting

awk search/replace specific field, using variables for regexp & subsitution then overwrite file

Hello, I'm trying the solve the following problem. I have a file which I intend to use as a csv called master.csv The columns are separated by commas. I want to change the text on a specific row in either column 3,4,5 or 6 from xxx to yyy depending upon if column 1 matches a specified pattern.... (3 Replies)
Discussion started by: cyphex
3 Replies

5. Shell Programming and Scripting

AWK replace one field

I have some problem with this. Need to change field #3 to 5 if field #1 = A and filed #2 =B DataA C 6 T C B 4 R A B 3 T D E 5 4 I would like to do two things if statement is true, but can not get it to work. Here it prints column #3 if statement is true, and this works awk '{if... (3 Replies)
Discussion started by: Jotne
3 Replies

6. Shell Programming and Scripting

How to print with awk specific field different from specific character?

Hello, i need help with awk. I have this file: cat number DirB port 67 er_enc_out 0 er_bad_os 0 DirB port 71 er_enc_out 56 er_bad_os 0 DirB port 74 er_enc_out 0 er_bad_os 0 DirB port 75 ... (4 Replies)
Discussion started by: elilmal
4 Replies

7. UNIX for Dummies Questions & Answers

How to replace and remove few junk characters from a specific field?

I would like to remove all characters starting with "%" and ending with ")" in the 4th field - please help!! 1412007819.864 /device/services/heartbeatxx 204 0.547%!i(int=0) 0.434 0.112 1412007819.866 /device/services/heartbeatxx 204 0.547%!i(int=1) 0.423 0.123... (10 Replies)
Discussion started by: snemuk14
10 Replies

8. Shell Programming and Scripting

awk to replace a specific field in certain condition

Hi, I have a file like below PRUM,67016800 ,CC ,C1,67016800 , ,Y,Y,2 ,CK,BX,FOX ,00000001,EA,00000001,20141120 00:00:00, ,N,Y,Y,CK ABCDEF... (7 Replies)
Discussion started by: mady135
7 Replies

9. Shell Programming and Scripting

awk - how to print specific field if a string is matched

hi gurus, I would like to be able to use awk to process 1 file as such: abc 1 2 3 4 5 6 7 8 9 10 flags 1 2 4 flags 1 2 5 abc 2 3 4 5 6 7 8 9 10 11 flags 1 2 3 abc 4 5 6 7 8 9 6 7 78 89 flags 1 2 3 flags 1 2 4 flags 1 2 3 4 I would like to be able to print field 1 and 5 when the... (4 Replies)
Discussion started by: revaroo
4 Replies

10. Shell Programming and Scripting

awk to add symbol to specific field

Trying to use awk to add a . to $4. The input and output is tab-delimeted, but the awk seems to add a . in front of $5 and is space-delimeted. It seems close, but I am not able to produce the desired output. Thank you :). file chr1 948895 949015 chr1:948895-949015 ISG15 chr1 ... (1 Reply)
Discussion started by: cmccabe
1 Replies
funtablerowput(3)						SAORD Documentation						 funtablerowput(3)

NAME
FunTableRowPut - put Funtools rows SYNOPSIS
int FunTableRowPut(Fun fun, void *rows, int nev, int idx, char *plist) DESCRIPTION
The FunTableRowPut() routine writes rows to a FITS binary table, taking its input from an array of user structs that contain column values selected by a previous call to FunColumnSelect(). Selected column values are automatically converted from native data format to FITS data format as necessary. The first argument is the Fun handle associated with this row data. The second rows argument is the array of user structs to output. The third nrow argument specifies the number number of rows to write. The routine will write nrow records, starting from the location speci- fied by rows. The fourth idx argument is the index of the first raw input row to write, in the case where rows from the user buffer are being merged with their raw input row counterparts (see below). Note that this idx value is has nothing to do with the row buffer specified in argument 1. It merely matches the row being written with its corresponding (hidden) raw row. Thus, if you read a number of rows, process them, and then write them out all at once starting from the first user row, the value of idx should be 0: Ev ebuf, ev; /* get rows -- let routine allocate the row array */ while( (ebuf = (Ev)FunTableRowGet(fun, NULL, MAXROW, NULL, &got)) ){ /* process all rows */ for(i=0; i<got; i++){ /* point to the i'th row */ ev = ebuf+i; ... } /* write out this batch of rows, starting with the first */ FunTableRowPut(fun2, (char *)ebuf, got, 0, NULL); /* free row data */ if( ebuf ) free(ebuf); } On the other hand, if you write out the rows one at a time (possibly skipping rows), then, when writing the i'th row from the input array of rows, set idx to the value of i: Ev ebuf, ev; /* get rows -- let routine allocate the row array */ while( (ebuf = (Ev)FunTableRowGet(fun, NULL, MAXROW, NULL, &got)) ){ /* process all rows */ for(i=0; i<got; i++){ /* point to the i'th row */ ev = ebuf+i; ... /* write out the current (i.e., i'th) row */ FunTableRowPut(fun2, (char *)ev, 1, i, NULL); } /* free row data */ if( ebuf ) free(ebuf); } The final argument is a param list string that is not currently used. The routine returns the number of rows output. This should be equal to the value passed in the third nrow</B argument. When FunTableRowPut() is first called for a given binary table, Funtools checks to see of the primary header has already been written (either by writing a previous row table or by writing an image.) If not, a dummy primary header is written to the file specifying that an extension should be expected. After this, a binary table header is automatically written containing information about the columns that will populate this table. In addition, if a Funtools reference handle was specified when this table was opened, the parameters from this Funtools reference handle are merged into the new binary table header. In a typical Funtools row loop, you read rows using FunTableRowGet()() and write rows using FunTableRowPut(). The columns written by FunT- ableRowPut()() are those defined as writable by a previous call to FunColumnSelect(). If that call to FunColumnSelect also specified merge=[update|replace|append], then the entire corresponding raw input row record will be merged with the output row according to the merge specification (see FunColumnSelect() above). A call to write rows can either be done once, after all rows in the input batch have been processed, or it can be done (slightly less effi- ciently) one row at a time (or anything in between). We do recommend that you write all rows associated with a given batch of input rows before reading new rows. This is required if you are merging the output rows with the raw input rows (since the raw rows are destroyed with each successive call to get new rows). For example: Ev buf, ev; ... /* get rows -- let routine allocate the row array */ while( (buf = (Ev)FunTableRowGet(fun, NULL, MAXROW, NULL, &got)) ){ /* point to the i'th row */ ev = buf + i; .... process } /* write out this batch of rows */ FunTableRowPut(fun2, buf, got, 0, NULL); /* free row data */ if( buf ) free(buf); } or Ev buf, ev; ... /* get rows -- let routine allocate the row array */ while( (buf = (Ev)FunTableRowGet(fun, NULL, MAXROW, NULL, &got)) ){ /* process all rows */ for(i=0; i<got; i++){ /* point to the i'th row */ ev = buf + i; ... process /* write out this batch of rows with the new column */ if( dowrite ) FunTableRowPut(fun2, buf, 1, i, NULL); } /* free row data */ if( buf ) free(buf); } Note that the difference between these calls is that the first one outputs got rows all at once and therefore passes idx=0 in argument four, so that merging starts at the first raw input row. In the second case, a check it made on each row to see if it needs to be output. If so, the value of idx is passed as the value of the i variable which points to the current row being processed in the batch of input rows. As shown above, successive calls to FunTableRowPut() will write rows sequentially. When you are finished writing all rows in a table, you should call FunFlush() to write out the FITS binary table padding. However, this is not necessary if you subsequently call FunClose() with- out doing any other I/O to the FITS file. Note that FunTableRowPut() also can be called as FunEventsPut(), for backward compatibility. SEE ALSO
See funtools(7) for a list of Funtools help pages version 1.4.2 January 2, 2008 funtablerowput(3)
All times are GMT -4. The time now is 11:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy