General :: Using Sort And Uniq In Bash?
Feb 18, 2011
I have this file with the first lines as follows:
a
a
ability
able
[code]....
say the file is named file1.txt After i do the following:
sort file1.txt | uniq >> file2.txt
I expect that letter a would only appear once, not in two rows, word about would also appear only once. However, I can't seem to get that result using this. I also tried the sort -f file1.txt | uniq >> file2.txt but to no avail. I actually got file1.txt from a messier file using the -f option in sort command.
View 2 Replies
ADVERTISEMENT
Nov 16, 2010
I have multiple strings (eg. say two, firstLIST=(0 1 2) and secondLIST=(2 3)) and want to create a single string composed of their unique sorted elements. For the sample strings above, I'd like to build masterLIST=(0 1 2 3).I suppose I could write the elements of firstLIST and secondLIST to files
Code:
echo ${firstLIST[@]} > firstFILE
echo ${secondLIST[@]} > secondFILE
then use
Code:
sort firstFILE secondFILE | uniq > masterFILE
as this gives me a file populated with the elements I'm after, but I'm not sure how to read the elements back into masterLIST... and it doesn't seem "right" to create files to accomplish this. Is there a way to do this by manipulating the strings ${firstLIST[@]} and ${secondLIST[@]} directly? The closest I've come (not close at all) is
Code:
masterLIST=${firstLIST[@]}" "${secondLIST[@]}
but masterLIST built this way has only one element
Code:
$echo ${masterLIST[@]}
0 1 2 2 3
$echo ${#masterLIST[@]}
1
and I don't have access to the individual digits to then try to figure out how to remove duplicates.
View 4 Replies
View Related
Feb 28, 2010
What options should I use when I'm using the sort command to sort the top 5 CPU processes (ps -eo user,pid,ppid,%cpu,%mem,fname | sort ??? | head -5) showing max to min usage?
View 2 Replies
View Related
May 18, 2010
i have a list of files in a folder. the list of files is displayed using:
now, i want to pipe that to uniq so it'll ignore the first 6 charactes before comparing. is it possible? or perhaps i need to use another command?
View 2 Replies
View Related
Jul 25, 2011
I am in need of sorting the content of a csv-file separated with "#". The file looks the following:
Code:
Descriptive 1#47.5498295127948#35.5365757501888#44.4127802931231#84.0767444257134#0.0416435951243528#0
[code]...
View 8 Replies
View Related
Sep 4, 2010
i currently have hundreds of files all in a single directory. What I would like to do is create 8 subdirectories and move the files into the subdirectories based on the first character of the file name. Ideally, the script would omit any 'the' or 'a' and use the second word for filing purposes. No filenames have spaces. Instead they use periodsThe subdirectories will be:
0-9
a-d
e-h
[code]...
View 2 Replies
View Related
Apr 29, 2010
I have for example the following IP addresses:
24.172.220.218
41.239.36.19
63.215.202.234
66.176.124.22
[code]....
How can I sort those IP addresses? I want to sort them using the first 3 numbers I also want to count the number of times that address is repeated This is a batch program.
View 4 Replies
View Related
Dec 9, 2009
I've been using linux for a long time, and I just ran into a problem that has me stumped. Any time I mistype a command, it says "Command not found."... yea, I know that's normal. But it doesn't return me to my # prompt. I have to press Ctrl+C to get back. code...
I know I do have one issue with this computer, I have 2 blown caps on my motherboard. This was a dual boot system, but after a virus with winblows, I decided to switch it to strictly linux. (roommates... *grumble*) I think I was running fc10 before I wiped the hd & installed fc12. Fc12 does seem to be running slower, and I still haven't got my sound card working properly... but that issue is for another topic...
-YungBlood Reborn
View 2 Replies
View Related
Sep 28, 2010
I have very little linux experience. And need some help with a bash script. I need to a script I can set cron to run to sort files out of a holding folder into final folders. It doesn't necessarily have to be bash, but I think it would be sufficient for this. File names are formatted as such when created: Dest-Date-Time-CID-Destination# I want the files to be moved from a all in one holding folder to a folder structure like this.
.../storage/year/month/day/Destination#/VarX(type)/hour/CID/'File'
I would need an if/else if/else statement to say if Dest = A set VarX = B If for example the file name was
infinity-20100927-17:00-1112223333-4445556666.wav
I would like the above file to end up moved from
.../holding
to
.../storage/2010/09/27/4445556666/Inbound/17/1112223333/infinity-20100927-17:00-1112223333-4445556666.wav
So the script will need to make directories based on information in the file name which is delimited by single dashes. Then move files from the holding folder to the newly created "sorted" folders.
View 15 Replies
View Related
Aug 18, 2010
I'm trying to make another file annotation script a little speedier than it has been by the up-until-now proven method of checking the last four characters in a filename before the "dot" (eg .jpg, .psd) against a list of known IPTC categories and Exiv2 command files. It occurred to me that if one script generated a list of files in directory foo, and the same or another script sorted that list by that four-letter tag,then that list could be used(instead of a for/do/done loop on the real files in the folder) by the command-file-matching script to "vomit out" which annotator file would go with file nastynewfile.jpg, f'r'instance. The script I had been using for this task looks like this:
Code:
while read 'line';
do
sp=$(echo $line)
vc=$(echo $sp | cut -d"," -f1)
cv=$(echo $sp | cut -d"," -f2)
[code]....
Where I seem to be stuck is with how to sort the lines in templist, which may be any number of different lengths, from back to front. sort -k looked promising, except it seems only to work the other way round. I thought of invoking a
Code:
q=$(expr length $line); echo $q
n=$[q-8]; echo $n
kind of thing, but that presented the problems of how to sort by those, how to tell sort where to find them (grep?) and how to "stitch them back in" to the original list, which is what I want to sort in the first place.
View 14 Replies
View Related
Nov 29, 2010
I create a bash script that writes another bash file. But in the generated bash file I want to write a bash command in the file and not executing it.Here's my bash file:
Code:
#!/bin/bash
cat > ~/generateGridmix2data.sh << END
[code]...
View 6 Replies
View Related
Jul 17, 2010
below are the details of my system. I have bash as my current shell, some really common commands aren't working.
Do I need to do a re-installation of bash? Or how do I install a selection of bash commands which I need? (for example a subset of [URL])
Code:
root@sdptfw:~ # uname -a
Linux sdptfw.sdpt.co.za 2.4.36 #1 Tue Jul 22 13:13:24 GMT 2008 i686 i686 i386 GNU/Linux
root@sdptfw:~ # echo $SHELL$
/bin/bash$
[Code]....
View 13 Replies
View Related
May 4, 2010
We switched from unix to linux and we have an old report that extracted data from a database, output to an ascii file and then sorted the results in the file based on different arguments. The report now blows up when it runs,and I can only guess it is because the options for sort on linux differ slightly from unix.For example, here is one of the commands issued from within the report app that ran on the old unix box:
if sort-sequence = "descending" then
'sort -t~" -f +3.0f -4.0 +5.0r -6.0 -f '
else
'sort -t~" +3.0f -4.0 +1.0f -2.0 -f'
I will eventually rewrite the report to store the data in a local table, but I can simply adjust the options to suit the requirments of linux. Basically, I need to know if this can be a quick fix for the short term.
View 2 Replies
View Related
Dec 3, 2010
What happens when the script executes is that the ssh connection works and parks me at the remote hosts's shell login. Therefore, the "firefox" command refuses to execute. I need to know how to make the "ssh" connection occur, stay open, and go into the background so that the rest of the script can execute.If I could also do this with the "firefox" line so that the entire term window could be closed would also be helpful.
View 3 Replies
View Related
Sep 11, 2011
The GNU sort text utility features a non-standard -R option to randomize input lines (presumably by sorting on a hash).
OSX sort does not have this extension. Is there similar functionality available in another text filter?
View 1 Replies
View Related
Jun 28, 2011
I am using expect command to pass password to my script.
like code...
it will send password properly, but after that it will not come out of expect to bash.
View 4 Replies
View Related
Mar 5, 2010
I was not able to install svn on Fedora 9, it gives a warning APR not found. Which svn version would be compatible?
View 2 Replies
View Related
May 14, 2010
How can I list directories with ls and sort them by their owner and group?
View 1 Replies
View Related
Aug 20, 2010
The sort utility in Ubuntu 10.04 (Lucid) always sort by case-insensitive, just like if you specify --ignore-case to it. The two sort just give the same result:
[Code]....
But sometimes I want to sort by case-sensitive, so the upper-case letters come first, then lower-case letter.
View 2 Replies
View Related
Apr 27, 2011
How can you make htop sort the list of processes by PID?
View 2 Replies
View Related
Jun 11, 2011
For Linux command sort, how do I force sort to load all input into memory and sort assuming I have enough memory? Or is it best to use a RAMDISK to store the input before feeding it to sort?
View 3 Replies
View Related
Oct 1, 2009
I am using Red hat linux .. i just wanted to know, is it possible to arrange or sort filenames numerically?i have saved several files with the follwing names : 1.png, 2.png, 3.png, 4.png ...... 11.png 12.png. and so on.... but the containing folder sorts this alphabetically in the following manner 11,12,13...... 1, 2, 3, and so on...
View 6 Replies
View Related
Apr 6, 2010
How to configure yum in centos.
its easily possible in rhel 5.0
View 3 Replies
View Related
Mar 12, 2010
I've been using Linux Mint happily for a while until a couple of days ago it just died. Froze up, nothing I could do would free it up other than a hard reset. So, I tried to install it again from a Live CD, but my laptop won't even boot into Live mode. It just sits there, saying 'Loading....'. which it frankly isn't. I suspect a major hardware fault has occurred, but have no idea what. Any ideas?
View 1 Replies
View Related
Dec 19, 2010
I'm struck with the following problem.
I have a data file with following data code...
(I have bigger data that needs to check all the above conditions)
get a code for the above problem
(either a shell code or a c-program)
View 2 Replies
View Related
Feb 22, 2010
I am getting little bit difficult in sorting the date ranges which are in a field like:
How make a sort as per the Month and date , i mean result should be as per the month and date wise. If i go for the sort -M , i am not able to get the list as per date of the particular month.
View 4 Replies
View Related
Mar 30, 2010
How do I sort the output of du by its first column. I issue the command this way:$ du.Is there a way?
View 5 Replies
View Related
Feb 1, 2011
I am using Ubuntu 10.10 maverick meekat...suddenly terminal cannot be launched.
View 8 Replies
View Related
Dec 21, 2010
I am reading a tool manual and it instructs to use such a command:
Code:
Especially, what does the 'sort' parameters and awk do?
View 8 Replies
View Related
Feb 3, 2010
In my CentOS 5.4 installation i configure it as a server GUI and click the updates box and go to the configure now option and click the internet box but it just says getting packages or something like that and i never does.
View 6 Replies
View Related