02-17-2012
There's a nice trimString() function in blib (the bash library link-> //bit.ly/i7tZWH) that does this. Of course it's still under development so your mileage may vary.
Essentially you can use something like... ${1:0:$((${#1}-1))}.
Note the subshell call may no be necessary...
Cheers,
Mikel King
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I've made a script to grep a file
for i in `cat filename.txt`
do
strings ./binfile | grep "$i" 2>&1 > /dev/null
done
this works fine as long as in filename.txt i don't have any entries with spaces. But in my case i want to grep something with spaces like "lala tata"
and... (3 Replies)
Discussion started by: papasj
3 Replies
2. Shell Programming and Scripting
hi
I have a list of words in a text file. these words are appended by "." at their end. They look something like this.
word1.
word2.
word3.
word4.
word5.
I need to remove the last character "." from all the words. The output must look something like this.
word1
word2
word3... (7 Replies)
Discussion started by: ss3944
7 Replies
3. Shell Programming and Scripting
Hi all,
Does anyone know how to code in ksh that will remove the first character in a string variable and replace that variable without the first character?
Example:
var1=ktest1 will become var1=test1
var2=rtest2 will become var2=test2
Need help please. (10 Replies)
Discussion started by: ryukishin_17
10 Replies
4. Shell Programming and Scripting
Hello,
The last character is a comma ,
I have tried the following:
sed -e 's/\,$//' filename-to-read
however - there are still commas at the end of each line...:confused: (5 Replies)
Discussion started by: learning
5 Replies
5. Shell Programming and Scripting
Hello!
Please bare with me, I'm a total newbie to scripting. Here's the sudo code of what I'm trying to do:
Get file name
Does file exist?
If true
get length of file name
get network id (this will be the last 3 numbers of the file name)
loop x 2
If... (1 Reply)
Discussion started by: KatieV
1 Replies
6. Shell Programming and Scripting
Hi there,
i need some help to remove all occurrences of a certain character at the beginning of a string.
Example: my string is 00102030 and i want to remove all zeros from beginning of string so the result is 102030 (3 Replies)
Discussion started by: gigagigosu
3 Replies
7. Shell Programming and Scripting
How can i remove the first and last character of strings like below:
"^^^613*"
"admt130"
"^^^613*"
"123456"
"adg8484"
"DQitYV09dh1C"
Means i wanna remove the quotes("").
Please help (17 Replies)
Discussion started by: proactiveaditya
17 Replies
8. Shell Programming and Scripting
I am outputting a line like this
print $2 "/" $4The last character though is a ":" and I want to remove it. Is there any neat way to remove it? Or am I forced to do something like this:
print $2 "/" substr($4, 1, length($4) - 1)Thanks. (6 Replies)
Discussion started by: benalt
6 Replies
9. UNIX for Beginners Questions & Answers
hello !
I have to remove string between a number and set of characters. For example,
35818 -stress - - -stress - - - - - - DB-3754
44412 caul kid notify DB-3747
54432 roberto -, notify DB-3725
55522 aws _ _int _ _classified 2_a _a 2_m _m 2_classified 2_search... (7 Replies)
Discussion started by: ManoharMa
7 Replies
10. UNIX for Beginners Questions & Answers
Hi,
I am new in bash scripting. In my work, I provide support to several users and when I connect to their computers I use the same admin and password, so I am trying to create a script that will only ask me for the IP address and then connect to the computer without having me to type the user... (5 Replies)
Discussion started by: arcoa05
5 Replies
NICE(2) Linux Programmer's Manual NICE(2)
NAME
nice - change process priority
SYNOPSIS
#include <unistd.h>
int nice(int inc);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
nice(): _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE
DESCRIPTION
nice() adds inc to the nice value for the calling process. (A higher nice value means a low priority.) Only the superuser may specify a
negative increment, or priority increase. The range for nice values is described in getpriority(2).
RETURN VALUE
On success, the new nice value is returned (but see NOTES below). On error, -1 is returned, and errno is set appropriately.
ERRORS
EPERM The calling process attempted to increase its priority by supplying a negative inc but has insufficient privileges. Under Linux the
CAP_SYS_NICE capability is required. (But see the discussion of the RLIMIT_NICE resource limit in setrlimit(2).)
CONFORMING TO
SVr4, 4.3BSD, POSIX.1-2001. However, the Linux and (g)libc (earlier than glibc 2.2.4) return value is nonstandard, see below. SVr4 docu-
ments an additional EINVAL error code.
NOTES
SUSv2 and POSIX.1-2001 specify that nice() should return the new nice value. However, the Linux syscall and the nice() library function
provided in older versions of (g)libc (earlier than glibc 2.2.4) return 0 on success. The new nice value can be found using getprior-
ity(2).
Since glibc 2.2.4, nice() is implemented as a library function that calls getpriority(2) to obtain the new nice value to be returned to the
caller. With this implementation, a successful call can legitimately return -1. To reliably detect an error, set errno to 0 before the
call, and check its value when nice() returns -1.
SEE ALSO
nice(1), renice(1), fork(2), getpriority(2), setpriority(2), capabilities(7)
COLOPHON
This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
Linux 2007-07-26 NICE(2)