Sponsored Content
Top Forums Shell Programming and Scripting Remove duplicates and update last 2 digits of the original row with 0's Post 302655707 by farawaydsky on Wednesday 13th of June 2012 02:57:26 PM
Old 06-13-2012
Lightbulb Remove duplicates and update last 2 digits of the original row with 0's

Hi,

I have a requirement where I have to remove duplicates from a file based on the first 8 chars (It is fixed width file of 10 chars length) and whenever a duplicate row is found, its original row's last 2 chars should be updated to all 0's.


I thought of using
Code:
sort -u -k 1.1,1.8 inputfile

but that will give me the result after remove duplicates and with the original last digits as is for the duplicate records

here is the sample input and output

Quote:
input:
1251233Y34
1221249N21
1231116Y45
1231116Y23
1231116N12

output should be:
1251233Y34
1221249N21
1231116Y00
1231116N12
Any help in achieving the above result using either awk/sed will be greatly appreciated.

Thanks,
Faraway
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Testing Var for 3 digits in a row only

Hi, I want to test a var, $inputPin to see if is 3 digits in a row or not in a Bash script. I am getting stuck on the regex to do this. And the equality test if it is in an if statement as below? -ne is for comparing numbers But I guess it would be != in this case if \{3,3\]}] ... (6 Replies)
Discussion started by: de_la_espada
6 Replies

2. Shell Programming and Scripting

remove row if string is same as previous row

I have data like: Blue Apple 6 Red Apple 7 Yellow Apple 8 Green Banana 2 Purple Banana 8 Orange Pear 11 What I want to do is if $2 in a row is the same as $2 in the previous row remove that row. An identical $2 may exist more than one time. So the out file would look like: Blue... (4 Replies)
Discussion started by: dcfargo
4 Replies

3. UNIX for Dummies Questions & Answers

CSV file:Find duplicates, save original and duplicate records in a new file

Hi Unix gurus, Maybe it is too much to ask for but please take a moment and help me out. A very humble request to you gurus. I'm new to Unix and I have started learning Unix. I have this project which is way to advanced for me. File format: CSV file File has four columns with no header... (8 Replies)
Discussion started by: arvindosu
8 Replies

4. Shell Programming and Scripting

remove directories with two digits after decimal point

Hi everyone, I am new here and generally not experienced with linux. My question must be easy, but as for now I have no idea how to do it. I have lots of directories with numerical names, e.g. 50 50.1 50.12 etc. What I want is to leave directories with no or single digit after the decimal... (2 Replies)
Discussion started by: cabaciucia
2 Replies

5. Shell Programming and Scripting

Identify duplicates and update the last 2 digits to 0 for both the Orig and Dup

Hi, I have a requirement where I have to identify duplicates from a file based on the first 6 chars (It is fixed width file of 12 chars length) and whenever a duplicate row is found, its original and duplicate row's last 2 chars should be updated to all 0's if they are not same. (I mean last 2... (3 Replies)
Discussion started by: farawaydsky
3 Replies

6. Shell Programming and Scripting

Remove all digits and rename a file

Hi, I have a file nexus-1234 in a directory. I want to generate a random number and replace the 1234 with it and rename the file. So nexus-1234 becomes nexus-2863 after running the script. Any help is appreciated. Thanks in advance. (2 Replies)
Discussion started by: scorpioraghu
2 Replies

7. Shell Programming and Scripting

Remove duplicates within row and separate column

Hi all I have following kind of input file ESR1 PA156 leflunomide PA450192 leflunomide CHST3 PA26503 docetaxel Pa4586; thalidomide Pa34958; decetaxel docetaxel docetaxel I want to remove duplicates and I want to separate anything before and after PAxxxx entry into columns or... (1 Reply)
Discussion started by: manigrover
1 Replies

8. Shell Programming and Scripting

Need to print duplicate row along with highest version of original

There are some duplicate field on description column .I want to print duplicate row along with highest version of number and corresponding description column. file1.txt number Description === ============ 34567 nl21a00is-centerdb001:ncdbareq:Error in loading init 34577 ... (7 Replies)
Discussion started by: vijay_rajni
7 Replies

9. Shell Programming and Scripting

Trying to remove duplicates based on field and row

I am trying to see if I can use awk to remove duplicates from a file. This is the file: -==> Listvol <== deleting /vol/eng_rmd_0941 deleting /vol/eng_rmd_0943 deleting /vol/eng_rmd_0943 deleting /vol/eng_rmd_1006 deleting /vol/eng_rmd_1012 rearrange /vol/eng_rmd_0943 ... (6 Replies)
Discussion started by: newbie2010
6 Replies

10. Shell Programming and Scripting

Splitting single row into multiple rows based on for every 10 digits of last field of the row

Hi ALL, We have requirement in a file, i have multiple rows. Example below: Input file rows 01,1,102319,0,0,70,26,U,1,331,000000113200000011920000001212 01,1,102319,0,1,80,20,U,1,241,00000059420000006021 I need my output file should be as mentioned below. Last field should split for... (4 Replies)
Discussion started by: kotra
4 Replies
ODBC_FETCH_ROW(3)							 1							 ODBC_FETCH_ROW(3)

odbc_fetch_row - Fetch a row

SYNOPSIS
bool odbc_fetch_row (resource $result_id, [int $row_number]) DESCRIPTION
Fetches a row of the data that was returned by odbc_do(3) or odbc_exec(3). After odbc_fetch_row(3) is called, the fields of that row can be accessed with odbc_result(3). PARAMETERS
o $result_id - The result identifier. o $row_number - If $row_number is not specified, odbc_fetch_row(3) will try to fetch the next row in the result set. Calls to odbc_fetch_row(3) with and without $row_number can be mixed. To step through the result more than once, you can call odbc_fetch_row(3) with $row_number 1, and then continue doing odbc_fetch_row(3) without $row_number to review the result. If a driver doesn't support fetching rows by number, the $row_number parameter is ignored. RETURN VALUES
Returns TRUE if there was a row, FALSE otherwise. PHP Documentation Group ODBC_FETCH_ROW(3)
All times are GMT -4. The time now is 11:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy