Sponsored Content
Top Forums Shell Programming and Scripting Identify duplicates and update the last 2 digits to 0 for both the Orig and Dup Post 302656849 by binlib on Friday 15th of June 2012 01:26:15 PM
Old 06-15-2012
Code:
sort -k1.1,1.6 inputfile |awk '
{
  if (substr($0,1,6) == substr(x,1,6) &&
        substr($0,11,2) != substr(x,11,2)) {
    sub(/..$/, "00", x)
    sub(/..$/, "00")
  }
  if (x) print x
  x = $0
}
END { if (x) print x }'

 

9 More Discussions You Might Find Interesting

1. Programming

dup()

Would anyone be so kind to explain to me the function of dup() in UNIX? As far as I am concerned, it duplicates a file descriptor. Under what circumstances would we need to duplicate a file descriptor in a UNIX environment? Thank you. vinchen (3 Replies)
Discussion started by: vinchen
3 Replies

2. Programming

fork() and dup()

I have met this code: switch(fork()) { case 0: close(1); dup(p); close(p); close(p); execvp(<whatever>); perror("Exec failed"); } Can anyone tell me what this piece of code does? Thx alot.. (1 Reply)
Discussion started by: AkumaTay
1 Replies

3. Shell Programming and Scripting

archive with .orig extension

i am moving old file from folder to archive file by this command ls -rt | grep -v '^archive$' | sed '$d' | xargs -I{} mv {} archive can I add .orig extension to all file and then move into archive folder. Where would be adjectly I place my syntex. (1 Reply)
Discussion started by: u263066
1 Replies

4. Programming

dup()

when i want to replace standard output with output file int out; out = open("out", O_WRONLY)p; dup2(out,1); What Shall I do in case of appending??? I am using here O_WRONLY TO WRITE.BUT IF i wanna append, whats the word? (5 Replies)
Discussion started by: joey
5 Replies

5. Shell Programming and Scripting

help: single digits inflated to 2 digits

Hi Folks Probably an easy one here but how do I get a sequence to get used as mentioned. For example in the following I want to automatically create files that have a 2 digit number at the end of their names: m@pyhead:~$ for x in $(seq 00 10); do touch file_$x; done m@pyhead:~$ ls file*... (2 Replies)
Discussion started by: amadain
2 Replies

6. Red Hat

ping error (DUP!)

Ntop is running on redhat. But It gives DUP! error while pinging to any places I dont know why DUP! error is occured. # ping google.com PING google.com (74.125.39.147) 56(84) bytes of data. 64 bytes from fx-in-f147.1e100.net (74.125.39.147): icmp_seq=1 ttl=44 time=54.1 ms 64 bytes from... (6 Replies)
Discussion started by: getrue
6 Replies

7. Shell Programming and Scripting

Find filenames with three digits and add zeros to make five digits

Hello all! I've looked all over the internet and this site and have come up a loss with an easy way to make a bash script to do what I want to do. I have a file with a naming convention as follows: 2012-01-18 string of words here 123.jpg 2012-01-18 string of words here 1234.jpg 2012-01-18... (2 Replies)
Discussion started by: Buzzman25
2 Replies

8. Shell Programming and Scripting

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 sort -u -k 1.1,1.8... (4 Replies)
Discussion started by: farawaydsky
4 Replies

9. UNIX for Beginners Questions & Answers

sed / awk script to delete the two digits from first 3 digits

Hi All , I am having an input file as stated below 5728 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r03_q_reg_20_/Q 011 611 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 011 3486... (4 Replies)
Discussion started by: kshitij
4 Replies
DUP(2)								System Calls Manual							    DUP(2)

NAME
dup, dup2 - duplicate a descriptor SYNOPSIS
#include <unistd.h> int dup(int oldd) int dup2(int oldd, int newd) DESCRIPTION
Dup duplicates an existing descriptor. The argument oldd is a small non-negative integer index in the per-process descriptor table. The value must be less than OPEN_MAX, the size of the table. The new descriptor returned by the call, let's name it newd, is the lowest num- bered descriptor that is not currently in use by the process. The object referenced by the descriptor does not distinguish between references using oldd and newd in any way. Thus if newd and oldd are duplicate references to an open file, read(2), write(2) and lseek(2) calls all move a single pointer into the file, and append mode, non- blocking I/O and asynchronous I/O options are shared between the references. If a separate pointer into the file is desired, a different object reference to the file must be obtained by issuing an additional open(2) call. The close-on-exec flag on the new file descriptor is unset. In the second form of the call, the value of newd desired is specified. If this descriptor is already in use, the descriptor is first deallocated as if a close(2) call had been done first. Newd is not closed if it equals oldd. RETURN VALUE
The value -1 is returned if an error occurs in either call. The external variable errno indicates the cause of the error. ERRORS
Dup and dup2 fail if: [EBADF] Oldd or newd is not a valid active descriptor [EMFILE] Too many descriptors are active. NOTES
Dup and dup2 are now implemented using the F_DUPFD function of fcntl(2), although the old system call interfaces still exist to support old programs. SEE ALSO
open(2), close(2), fcntl(2), pipe(2). 4th Berkeley Distribution May 13, 1986 DUP(2)
All times are GMT -4. The time now is 10:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy