Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Replacing values in a column if they equal a certain value Post 302834299 by evelibertine on Thursday 18th of July 2013 04:22:57 PM
Old 07-18-2013
Replacing values in a column if they equal a certain value

Hi,

I have a tab delimited text file where some lines have the string "NA" in the second column. For these lines, I want to replace NA with the value in the first column, the symbol underscore followed by the value in the fourth column. How do I go about doing that? Thanks!

Input:

Code:
1       rs1933024       0       244859  0       2
1       NA      0       608390  0       2
1       rs12565286      0       761153  0       2
1       NA      0       763682  0       2


Output
Code:
1       rs1933024       0       244859  0       2
1       1:608930      0       608390  0       2
1       rs12565286      0       761153  0       2
1       1:763682      0       763682  0       2

Thanks!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

My Values are Equal but They are Not

Does anybody understand why this is not being interpreted as true. Script: #!/bin/bash errored=`grep "errored" new_update_scripts.txt` echo $errored = "errored" if ; then echo true else echo false fi Output: $ UpdateScripts errored = errored false (7 Replies)
Discussion started by: scottwmackey
7 Replies

2. Shell Programming and Scripting

compare columns for equal values and output a summary

Hi all I am trying to scan a file that has 3 columns: red blue 123351 red blue 848655 red blue 126354 red blue 023158 black white 654896 red blue 650884 I want an output that sums the rows that have matching columns 1 and 2 :wall: red blue has 5 entries black white has 1 entry ... (4 Replies)
Discussion started by: reno
4 Replies

3. Shell Programming and Scripting

Replacing column 1 in one file with values in other file

Please help me with an shell / awk script to achieve following; File-1: ABCDW01 12322 23322 BDADW01 22232 24453 EDFAW00 32232 23422 and so on, notice that the first coloumn is a code and the another file contains the real value of each entry in the first colum above but not in a... (4 Replies)
Discussion started by: digipak
4 Replies

4. Shell Programming and Scripting

replacing negative values in a column with zero

Hi, i need help on replacing negative values in a column with 0. any quick fix on this? thanks much. for instance, input: 1 2.3 -0.4 -25 12 13 45 -12 desired output 1 2.3 0 0 12 13 45 (4 Replies)
Discussion started by: ida1215
4 Replies

5. Shell Programming and Scripting

Replacing column values

hi all , ( perl) i am trying to replace jst one column in a file for eg month dayofweek dealar car-name jan thurs mercedes c300 feb wed lexus is300 all this data is in a master file and i want to replace jan with 1 feb... (5 Replies)
Discussion started by: technoman
5 Replies

6. Shell Programming and Scripting

awk file to read values from Db2 table replacing hard coded values

Hi, I want to replace a chain of if-else statement in an old AWK file with values from Db2 table or CSV file. The part of code is below... if (start_new_rec=="true"){ exclude_user="false"; user=toupper($6); match(user, "XXXXX."); if (RSTART ==2 ) { ... (9 Replies)
Discussion started by: asandy1234
9 Replies

7. Shell Programming and Scripting

Replacing values into a single column. sed/PERL

Hello everyone, i need to replace in the second column of my csv file, points by nothing and dash by comma like this: Input: 1 2 1;12.111.312-2;1.2;2;1-3 2 1 1;11.212.331-1;3.3;1;2-2 Output: 1 2 1;12111312;2;1.2;2;1-3 2 1 1;11212331;1;3.3;1;2-2 SED or PERL commands preferably. ... (7 Replies)
Discussion started by: satir
7 Replies

8. Shell Programming and Scripting

Deleting consecutive equal values in a file

Hello everyone, I have a requirement as shown below. I need to delete consecutive same values from the source file and give it as output file. Source: a,b,c,d,e,e,f,g Target: a,b,c,d,f,g The repeating value "e" should be deleted from the file completely. How can I achieve this... (14 Replies)
Discussion started by: vamsikrishna928
14 Replies

9. UNIX for Dummies Questions & Answers

Help in replacing column values

Hello All, I am having the file as below .I need to replace column 9-12 with some other values. In the below file I need to replace 1509 to 1508 and 1508 to 1507 .Can you please help me in how to do that Thanks, Arun ... (10 Replies)
Discussion started by: arunkumar_mca
10 Replies

10. Shell Programming and Scripting

Delete row if both percentage values are equal to zero

Hello, I have compiled a script but I have stucked at one point. Each line contains two pcs of % value and what I want to do is to delete any line if both % values are zero. data: expected output: ow3 should be deleted as both percentage value in related line are equal to zero. ... (2 Replies)
Discussion started by: baris35
2 Replies
PR(1)							    BSD General Commands Manual 						     PR(1)

NAME
pr -- print files SYNOPSIS
pr [+page] [-column] [-adFmrt] [[-e] [char] [gap]] [-h header] [[-i] [char] [gap]] [-l lines] [-o offset] [[-s] [char]] [-T timefmt] [[-n] [char] [width]] [-w width] [-] [file ...] DESCRIPTION
The pr utility is a printing and pagination filter for text files. When multiple input files are specified, each is read, formatted, and written to standard output. By default, the input is separated into 66-line pages, each with o A 5-line header with the page number, date, time, and the pathname of the file. o A 5-line trailer consisting of blank lines. If standard output is associated with a terminal, diagnostic messages are suppressed until the pr utility has completed processing. When multiple column output is specified, text columns are of equal width. By default text columns are separated by at least one <blank>. Input lines that do not fit into a text column are truncated. Lines are not truncated under single column output. OPTIONS
In the following option descriptions, column, lines, offset, page, and width are positive decimal integers and gap is a nonnegative decimal integer. +page Begin output at page number page of the formatted input. -column Produce output that is columns wide (default is 1) that is written vertically down each column in the order in which the text is received from the input file. The options -e and -i are assumed. This option should not be used with -m. When used with -t, the min- imum number of lines is used to display the output. -a Modify the effect of the -column option so that the columns are filled across the page in a round-robin order (e.g., when column is 2, the first input line heads column 1, the second heads column 2, the third is the second line in column 1, etc.). This option requires the use of the -column option. -d Produce output that is double spaced. An extra <newline> character is output following every <newline> found in the input. -e [char][gap] Expand each input <tab> to the next greater column position specified by the formula n*gap+1, where n is an integer > 0. If gap is zero or is omitted the default is 8. All <tab> characters in the input are expanded into the appropriate number of <space>s. If any nondigit character, char, is specified, it is used as the input tab character. -F Use a <form-feed> character for new pages, instead of the default behavior that uses a sequence of <newline> characters. -h header Use the string header to replace the file name in the header line. -i [char][gap] In output, replace multiple <space>s with <tab>s whenever two or more adjacent <space>s reach column positions gap+1, 2*gap+1, etc. If gap is zero or omitted, default <tab> settings at every eighth column position is used. If any nondigit character, char, is specified, it is used as the output <tab> character. -l lines Override the 66 line default and reset the page length to lines. If lines is not greater than the sum of both the header and trailer depths (in lines), the pr utility suppresses output of both the header and trailer, as if the -t option were in effect. -m Merge the contents of multiple files. One line from each file specified by a file operand is written side by side into text columns of equal fixed widths, in terms of the number of column positions. The number of text columns depends on the number of file operands suc- cessfully opened. The maximum number of files merged depends on page width and the per process open file limit. The options -e and -i are assumed. -n [char][width] Provide width digit line numbering. The default for width, if not specified, is 5. The number occupies the first width column posi- tions of each text column or each line of -m output. If char (any nondigit character) is given, it is appended to the line number to separate it from whatever follows. The default for char is a <tab>. Line numbers longer than width columns are truncated. -o offset Each line of output is preceded by offset <spaces>s. If the -o option is not specified, the default is zero. The space taken is in addition to the output line width. -r Write no diagnostic reports on failure to open a file. -s char Separate text columns by the single character char instead of by the appropriate number of <space>s (default for char is the <tab> character). -T Specify an strftime(3) format string to be used to format the date and time information in the page header. -t Print neither the five-line identifying header nor the five-line trailer usually supplied for each page. Quit printing after the last line of each file without spacing to the end of the page. -w width Set the width of the line to width column positions for multiple text-column output only. If the -w option is not specified and the -s option is not specified, the default width is 72. If the -w option is not specified and the -s option is specified, the default width is 512. file A pathname of a file to be printed. If no file operands are specified, or if a file operand is '-', the standard input is used. The standard input is used only if no file operands are specified, or if a file operand is '-'. The -s option does not allow the option letter to be separated from its argument, and the options -e, -i, and -n require that both arguments, if present, not be separated from the option letter. ERRORS
If pr receives an interrupt while printing to a terminal, it flushes all accumulated error messages to the screen before terminating. The pr utility exits 0 on success, and 1 if an error occurs. Error messages are written to standard error during the printing process (if output is redirected) or after all successful file printing is complete (when printing to a terminal). SEE ALSO
cat(1), more(1), strftime(3) STANDARDS
The pr utility is IEEE Std 1003.2 (``POSIX.2'') compatible. BSD
June 6, 1993 BSD
All times are GMT -4. The time now is 02:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy