When I run a “last” command, I am getting more than one row per user.
Eg I need to transfer this file to an external application, and then import its contents to populate a new table.
Before doing so, I need to remove duplicates, leaving only the most recent entry, I also need to insert the “|” character between the fields, and remove all spaces, as the external application demands this convention for its import to work.
So the above would end up looking like : Is this possible, within a single unix script ?
Many thanks in anticipation.
Moderator's Comments:
Please use code tags - you got a PM how to do that.
Last edited by zaxxon; 12-16-2010 at 10:55 AM..
Reason: code tags
This as a start:
Having something like:
will not be very helpful if you tend to import it into a database table for example. There would be some replacing of the blanks between the date in such cases be involved. I have no good short idea to do this currently but I guess someone will have one ready
Thanks zaxxon for your prompt responses.
I have run your code, and it is certainly removing all the duplicates.
But I am still not getting a "|" command instead of the spaces separating the fields.
Any further advice would be most welcome.
Thanks again !
Thanks Franklin52.
Unfortunately, I am getting :- syntax error near line 1
bailing out near line 1
I created a script containing your code as follows :-
awk 'NF && !a[$1]++{NF=NF+1;print}' OFS="|" myfile
where myfile is the sorted output from the 'last' command.
Am I meant to set NF to a new file name ?
Or set [$1] to a runtime parameter ?
If so, what value ?
Sorry if any of this is obvious, but I am not an expert.
Thanks again for your help.
---------- Post updated at 12:41 PM ---------- Previous update was at 09:23 AM ----------
Greetings!
After block level migration using an external appliance, the luns are getting reported as DGC-RAID5 and these luns are infact from the new storage. I have a query on changing the device Vendor info from DGC-RAID5 to HP3par in the format o/p only.
AVAILABLE DISK SELECTIONS:
... (3 Replies)
How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address
and column 3 contains “cc” e-mail address to include with same email.
Sample input file, email.txt
Below is an sample code where... (2 Replies)
Hi All,
I tried searching a lot about this but to no avail. I have a HTML file. I used
links -dump file_page.html > text_html.txt
What the above command gave me was a filtered text from the HTML file with tags removed. Now, the the output from the above command looked something like this:... (1 Reply)
Hi,
I have line in input file as below:
3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL
My expected output for line in the file must be :
"1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL"
Can someone... (7 Replies)
Hello Team ,
I have to extract date section from the below file output. The output of the file is as shown below.
I have to extract the "" this section from the above output of the file. can anyone please let me know how can we acheive this? (4 Replies)
Can someone help me to convert the date format after get it from the "LAST REBOOT" command.
these is the standard output.
bash-3.00# last reboot
reboot system boot Fri Aug 6 15:07
reboot system down Fri Aug 6 15:04
reboot system boot ... (3 Replies)
Hi,
I have written a BASH shell script that contains a lot of "echo" commands to notify the user about what's going on. The script generates a log file that contains a copy of what is seen in the terminal. The echo statements are generally verbose, and thus extend out for quite a ways on one... (2 Replies)
Hi All,
I have working (Perl) code to combine 2 input files into a single output file using the join function that works to a point, but has the following limitations:
1. I am restrained to 2 input files only.
2. Only the "matched" fields are written out to the "matched" output file and... (1 Reply)
Hi All,
I am running my application on a dual cpu debian linux 3.0 (2.4.19 kernel).
For my application:
<sar -U ALL>
CPU %user %nice %system %idle
...
10:58:04 0 153.10 0.00 38.76 0.00
10:58:04 1 3.88 0.00 4.26 ... (0 Replies)