1828567 Members
2706 Online
109982 Solutions
New Discussion

Re: duplicates in a file

 
SOLVED
Go to solution
lawrenzo_1
Super Advisor

duplicates in a file

Hi all,

I am trying to write a small script but struggling what to use:

I have a file with the user id then some loggin info however this is duplicated for some instances ie:



time_last_login =
tty_last_login =
host_last_login =
unsuccessful_login_count =



i need to search the file to find the user id, keeep the first instance then delete the rest but I do not know howto search userid then delete 6 lines from where the uid is.

any ideas will be a great help.

Thanks
hello
5 REPLIES 5
Peter Godron
Honored Contributor

Re: duplicates in a file

lawrenzo,
Attached a little script, which may be a step towards your solution.

Peter Godron
Honored Contributor
Solution

Re: duplicates in a file

lawrenzo,
sorry, attachment missing.
Chan 007
Honored Contributor

Re: duplicates in a file

Hi,
Can you post the script that you are working on,

else use this command which will provide inputs that you are looking for in one line.

testos1:/usr/sbin/acct # ./fwtmp < /var/adm/wtmp
testos1:/usr/sbin/acct # ./fwtmp
Chan
Peter Nikitka
Honored Contributor

Re: duplicates in a file

Hi,

I don't know if the userid you mention is literally found as "" or "userid". My example assumes the latter case, but you can easily change this.

If you mean to keep the rest of the file without duplicate entries and a record consists of skip=6 lines:
awk -v us="userid" -v skip=6 '$1 == us {if(have_us) for(i=0;ihave_us++
}
{print}' myfile

To get only the first record of "userid" and nothing else:
awk -v us="userid" -v skip=6 '$1 == us {for(i=0;i
mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
lawrenzo_1
Super Advisor

Re: duplicates in a file

cheers guys

gordon and Peter your examples are cool.

Thanks
hello