I'm new to linux & bash so please forgive my ignorance, just wondering if anyone can help.
I have a file (mainfile.txt) with comma deliminated values, like so:
i need to split this file into two files. Any entries where the first number ($1) is in more than once needs to go in file1.txt. Any entries that only occur once need to go into file2.txt, like so:
File1.txt
File2.txt
Any solution to this problem would be greatly appreciated, no matter how implemented.
however, i would like to get experience using arrays so a solution incorporating them would be fantastic. i've experimented with them, like this, but cant get my head around them.
It's a botch job and not surprisingly doesnt work. even if it did, how do i specify $1 and only $1 as the thing to look at, instead of a string?
Cheers,
Ian
Last edited by Scott; 02-04-2011 at 12:05 PM..
Reason: Please use code tags
Thanks for the reply. It's almost there but not quite.
After running, my Files are as follows:
the t.tmp file is spot on - it know there's three instances of 613212 and one each of the others.
However, when it comes to sending them to files, file1.txt contains nothing when it should have three entries (all 613212) - and file2.txt should have the other two entries.
i've tried changing certain things but i'm shooting in the dark here.
Thanks again for helping.
Cheers
Ian
Last edited by Scott; 02-04-2011 at 01:23 PM..
Reason: Be a good fellow, and please use code tags.
Excuse my ignorance as I am very new to working with Solaris.
I'm looking for documentation on how to create a network log in Solaris 10 & 11. I don't wish to edit any of the logs currently the system. I simply want a log that will capture all incoming IP addresses and log them with a time-in... (8 Replies)
Hello
I have a problem.
I create a Multidimensional Array Like this:
ENTRY="$kunnum-$host"
ENTRY="$host"
ENTRY="# $3"
for key in "${!ENTRY}"; do
ENTRIES=${ENTRY} # INDEX=IP(5)
donedeclare -p
declare -A ENTRIES=(="unas15533" ="unas" ="# RDP-Terminal 2"... (12 Replies)
Hi,
Could anyone kindly show me a link or explain the difference between
sort -n -k2 -k3 & sort -n -k2,3
Also, if I like to remove the row with repetition at both $2 and $3, Can I safely use
sort -u -k2 -k3
Example;
100 20 30
100 20 30
So, both $2 and $3 are same and I... (2 Replies)
I have a dilemma, we have users who are copying files to "directory 1." These images have file names which include the year it was taken. I need to put together a script to do the following:
Examine the file naming convention, ensuring it's the proper format (e.g. test-1983_filename-123.tif)... (8 Replies)
Hi all,
I have the code as below "
echo "File carried list after 1st loop "${fileStreamAssiagnInit}""
and I have the out put for the above code as below :
Output : File carried list after 1st loop abcInd.csv sdgUS.csv sopSing.csv
Here i want to count the number of elements in... (3 Replies)
Hi !!
I'm rather new both to the UNIX and scripting worlds, and I'm learning the ropes of scripting. Having said this, please excuse me if you notice certain basic errors.
I'm working on a script that implements .jar and .war files for a WAS environment and I need to perform certain... (4 Replies)
cat file1.txt
field1 "user1":
field2:"data-cde"
field3:"data-pqr"
field4:"data-mno"
field1 "user1":
field2:"data-dcb"
field3:"data-mxz"
field4:"data-zul"
field1 "user2":
field2:"data-cqz"
field3:"data-xoq"
field4:"data-pos"
Now i need to have the date like below.
i have just... (7 Replies)
Hello!
I have a file with 4 columns. I am trying to have it sort first with respect to the first column, and then with respect to the number of counts (in descending count) in the second column within the same first column identity.
For example:
Input:
1 2 A 1
1 6 B 2
2 5 G 7
1 6 D 4... (8 Replies)
Hello!
I have a file with 4 columns. I am trying to have it sort first with respect to the first column, and then with respect to the number of counts (in descending count) in the second column within the same first column identity.
For example:
Input:
1 2 A 1
1 6 B 2
2 5 G 7
1 6 D 4
1... (1 Reply)
Hi,
I've a fixed width file where I need to count the number of patterns from each line between characters 1 to 15 . so can we sort them and get a count for each pattern on the file between 1 to 15 characters.
65795648617522383763831552 410828003265795648 6175223837... (5 Replies)