It's not at all clear what concept you are looking for. Perhaps you could elaborate on that a bit. In the meantime, here are some hopefully useful exercises.
The token duplicate removal is probably quite different from what you are imagining it would be, and has the unfortunate side effect of sorting the remaining tokens. In this case it doesn't matter, because they were already sorted, but nevertheless it's not a good general-purpose solution if the order of tokens is significant.
Perhaps you should read a tutorial on shell programming at this point; there's a lot of things you can do with variable substitution (${var%trim} is but a single example).
I am used to programming in Matlab and C++ and in these languages you can refer to individual members of a variable (array) and compare their values to all the other members using 2 loops. how can i accomplish that in unix. For example
var2=$(users)
will return the current users but if a user is running two instances of a shell then that username will be returned twice. How can i trim the varible $var2 so that multiple occurrences of usernames are eliminated. i can use a for loop to loop through each member of the varible but then how do i compare it to the rest of the usernames in $var2.
I am referring to tutorials as well but most of them jus explain the general syntax of commands. i guess i am not referring to the right ones, will work on tht.
In fact my sort | uniq example was not so far off the mark then.
A variable in Bourne classic is just a piece of text; some shells such as bash and ksh have array variables, too. The common trick would be to modify the text so it is in a suitable form by the time you assign it to a variable.
This should work as long as the output you want to process is whitespace-separated. You can play around with IFS= to use a different separator, but in the general case, it gets rather ugly and cumbersome.
For convenience, I made it so that $var2 will have one leading and one trailing space. Removing or ignoring those is left as an exercise.
The shell is not very good at these things; that's why awk and sed are more or less essential for nearly any moderately complex shell script. (Or use Perl if that helps at all.)
Modern shells have additional facilities, including an array variable type, but this approach works even with Bourne Classic. We are stuck with it, and in fact, we kind of like it, in spite of its oddities and quirks.
Hello,
I have a filename that looks like this:
ABC_96_20141031_041133.232468
I need to shorten only the "_2014" part of the filename to simply "_14" so the filename looks like:
ABC_96_141031_041133.232468
I have to do a search for this string because there are hundreds of files and... (17 Replies)
I have a script that currently runs fine and I need to add or || (or) condition to the if statement and I'm not sure the exact syntax as it relates to the use of brackets.
my current script starts like this:
errLog="/usr/local/website-logs/error.log"
apacheRestart="service httpd restart"... (3 Replies)
Hi,
I have a small piece of Makefile script which throw's error on Sun Sparc machine, but works fine with Sun Optron, Linux, AIX machines.
FOO=Naveen
test1:FOO=Dhilip
test1:
@echo FOO is ${FOO}
test2:
@echo Me is ${FOO}
Output on Sun Sparc -
ukhml-v890new-~/test: make test1... (5 Replies)
Hello everyone,
I have some data files, with mixed header formats. the sample for the same is:
>ABCD76567.x1
AGTCGATCGTAGTCGTAGCTGT
>ABCD76567.y1
AGTCGATCGTAGTCGTAGCTGT
>ABCD76568.x1 pair_info:898989
AGTCGATCGTAGTCGTAGCTGT
>ABCD76568.y1 pair_info:893489
AGTCGATCGTAGTCGTAGCTGT... (2 Replies)
Hi,
I have a file that looks something like this (2 columns 4 rows):
eeeeeeeeeeeeeeeeeeeeeeeeeeeee -45
rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr -24
ttttttttttttttttttttttttttttttttttttttttttt -29
uuuuuuuuuuuuuuuuuuuuuuuuuuu -23
How do I get it to look like this:
-45... (3 Replies)
Is there a command for finding all files on the system named ".bashrc" that modify the PS1 variable? I'd like to list the full file name(s) and the protection (including the full path). (5 Replies)
hi ,
I have a javascript file like this:
function fnValidateId(){
var array_id = new Array("444","7888","6633","555","146562","3333","33332")
var tmp_id = document.form1.id.value;
var num=0;
while(1)
{
if(tmp_id ==... (9 Replies)
Hello,
I have installed a new program called chimera under the directory /usr/local/bin/chimera.
the executable is under the directory /usr/local/bin/chimera/bin/chimera.e
If i put myself under the latest directiry and I type ./chimera, the program works.
I would like to avoid this and I... (1 Reply)
hello,
I have to communicate with a distant station . But Both belong to the same area. So I do not need a gate .
But when I make a traceroute, it indicates that I pass through out a gate.
What can I do to establish a direct connexion between the both.
(with NT ) (1 Reply)
In my /etc/profile, my $PATH variable is set as follows:
$PATH =/sbin:/usr/sbin:/usr/bin:/etc
Then how do I add an additional directory to it? say
/export/home/abd/rose
Please advise.
Thanks!
Deepali (3 Replies)