Sponsored Content
Top Forums Shell Programming and Scripting ksh String Manipulation - removing variables from within a variable Post 303029832 by MadeInGermany on Friday 1st of February 2019 12:42:29 PM
Old 02-01-2019
I pointed out earlier that // means "global". That makes sense because an empty search would not make sense.
Now RudiC opened my eyes for the /# and /% modifiers. Again, makes sense!

OMG bash-4 comes with even more modifiers:
Code:
 array=( john paul george ringo )
 for btl in ${array[@]}; do echo "$btl"; done 
john
paul
george
ringo
 for btl in ${array[@]^}; do echo "$btl"; done
John
Paul
George
Ringo
 for btl in ${array[@]^^}; do echo "$btl"; done
JOHN
PAUL
GEORGE
RINGO

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

extract from string variable into new variables

I have a variable which consists of a string like this: 001 aaabc 44 a bbb12 How do I extract each substring, delimited by the spaces, into new variables - one for each substring? eg var1 will be 001, var2 will be aaabc, var3 will be 44, var4 will be a, etc? I've come up with this:... (2 Replies)
Discussion started by: Sniper Pixie
2 Replies

2. Shell Programming and Scripting

KSH split string into variables

Hello, I am an intermediate scripter. I can usually find and adapt what I need by searching through previous postings, but I'm stumped. I have a string with the format "{Name1 Release1 Type1 Parent1} {Name2 Release2 Type2 Parent2}". It is being passed as an argument into a ksh script. I need to... (5 Replies)
Discussion started by: drd_2b
5 Replies

3. UNIX for Dummies Questions & Answers

String manipulation using ksh

I have a UNIX shell where: LEVEL=dev SITE=here and WHEREIAM=/tmp/$SITE/location/$LEVEL I want to echo $WHEREIAM in such a way that I get it back with all the environment variables resolved (/tmp/here/location/dev). This command will be used in a shell script. (5 Replies)
Discussion started by: zambo
5 Replies

4. Shell Programming and Scripting

string manipulation in ksh

Hi all, I'm trying to extract the name of a script that is being run with a full path. i.e. if the script name is /some/where/path/script_name.ksh I'd like to extract only: script_name i know that it is possible to do so in two phases: echo "${0##*/}" will give me script_name.ksh and... (4 Replies)
Discussion started by: iceman
4 Replies

5. Shell Programming and Scripting

Bash string variable manipulation

In a bash script I've set a variable that is the directory name of where an executable lives. the_dir=`dirname $which myscript` which equates to something like "/path/to/dir/bin" I need to cut that down to remove the "bin" so I now have "/path/to/dir/". This sounds easy but as a... (2 Replies)
Discussion started by: Witty
2 Replies

6. Shell Programming and Scripting

Bash:How to split one string variable in two variables?

Hello, I have a paramter $param consisting just of two literals and want to split it into two parameters, so I can combine it to a new parameter <char1><string><char2>, but the following code didn't work: tmp_PARAM_1=cut -c1 $PARAM tmp_PARAM_2=cut -c2 $PARAM... (2 Replies)
Discussion started by: ABE2202
2 Replies

7. Shell Programming and Scripting

Ksh in Linux Removing: "\0" From String

Hi All, I am facing a problem and I am not able to solve it. I have already searched google, but nothing (maybe I am not using the correct key words). As a database query result, I have a file like below: fmv:/home/fmv/tmp>cat TestBackRef.txt /^TEST\(\{4\}\)X\{12\}Y\.txt$/\0#\1/#Test... (2 Replies)
Discussion started by: felipe.vinturin
2 Replies

8. Shell Programming and Scripting

String manipulation using ksh script

Hi, I need to convert string "(joe.smith" into "joe_smith" i.e. I need to remove the leading opening brace '(' and replace the dot '.' with an under score '_' can anyone suggest a one liner ksh script or unix command for this please (3 Replies)
Discussion started by: sdj
3 Replies

9. Shell Programming and Scripting

How to convert string(variable) into date( epoch) in ksh on HPUX machine?

Hi all, I have used a bash script which ultimately converts a string into date using date --date option: DATE=$DATE" "$TIME" "`date +%Y` //concatenating 2 strings TMRW_DATE=`date --date="$DATE" +"%s"` //applying date command on string and getting the unixtime Please use code tags... (7 Replies)
Discussion started by: Rashu123
7 Replies

10. Shell Programming and Scripting

Variable string manipulation

Hi, I have a variable with grep output like this: WORDS=$(grep -r -c -i -E "palindrom" /"$DIRECTORY"/) so "echo "$WORDS"" could be: //directory/file1.txt:0 //directory/file2.txt:0 //directory/file3.txt:3 //directory/file4.txt:1 //directory/file5.txt:0 I need to "sed" my variable... (3 Replies)
Discussion started by: Hornys
3 Replies
project(4)							   File Formats 							project(4)

NAME
project - project file DESCRIPTION
The project file is a local source of project information. The project file can be used in conjunction with other project sources, includ- ing the NIS maps project.byname and project.bynumber and the LDAP database project. Programs use the getprojent(3PROJECT) routines to access this information. The project file contains a one-line entry for each project recognized by the system, of the form: projname:projid:comment:user-list:group-list:attributes where the fields are defined as: projname The name of the project. Allowable project names must begin with a letter, and may be composed of any letter or digit and the under- score character. The period ('.') is reserved for projects with special meaning to the operating system. projid The project's unique numerical ID (PROJID) within the system. The maximum value of the projid field is MAXPROJID. Project IDs below 100 are reserved for the use of the operating system. comment The project's description. user-list A comma-separated list of users allowed in the project. With the exception of the special projects referred to below, an empty field indicates no users are allowed. See note about the use of wildcards below. group-list A comma-separated list of groups of users allowed in the project. With the exception of the special projects referred to below, an empty field indicates no groups are allowed. See note about the use of wildcards below. attributes A semicolon-separated list of name value pairs. Each pair has the following format: name[=value] where name is the arbitrary string specifying the key's name and value is the optional key value. An explanation of the valid name- value pair syntax is provided in the USAGE section of this page. The expected most frequent use of the attribute field is for the spec- ification of resource controls. See resource_controls(5) for a description of the resource controls supported in the current release of the Solaris operating system. You can also use the attribute field for resource caps (see rcapd(1M)) and for the project.pool attribute (see setproject(3PROJECT)). Null entries (empty fields) in the user-list and group-list fields, which normally mean "no users" and "no groups", respectively, have a different meaning in the entries for three special projects, user.username, group.groupname, and default. See getprojent(3PROJECT) for a description of these projects. Wildcards can be used in user-list and group-list fields of the project database entry. The asterisk (*), allows all users or groups to join the project. The exclamation mark followed by the asterisk (!*), excludes all users or groups from the project. The exclamation mark (!) followed by a username or groupname excludes the specified user or group from the project. See EXAMPLES, below. Malformed entries cause routines that read this file to halt, in which case project assignments specified further along are never made. Blank lines are treated as malformed entries in the project file, and cause getprojent(3PROJECT) and derived interfaces to fail. EXAMPLES
Example 1: Sample project File The following is a sample project file: system:0:System::: user.root:1:Super-User::: noproject:2:No Project::: default:3:::: group.staff:10:::: beatles:100:The Beatles:john,paul,george,ringo::task.max-lwps= (privileged,100,signal=SIGTERM),(privileged,110,deny); process.max-file-descriptor Note that the two line breaks in the line that begins with beatles are not valid in a project file. They are shown here only to allow the example to display on a printed or displayed page. Each entry must be on one and only one line. An example project entry for nsswitch.conf(4) is: project: files nis With these entries, the project beatles will have members john, paul, george, and ringo, and all projects listed in the NIS project table are effectively incorporated after the entry for beatles. The beatles project has two values set on the task.max-lwps resource control. When a task in the beatles project requests (via one of its member processes) its 100th and 110th LWPs, an action associated with the encountered threshold triggers. Upon the request for the 100th LWP, the process making the request is sent the signal SIGTERM and is granted the request for an additional lightweight process (LWP). At this point, the threshold for 110 LWPs becomes the active threshold. When a request for the 110th LWP in the task is made, the requesting process is denied the request--no LWP will be created. Since the 110th LWP is never granted, the threshold remains active, and all subse- quent requests for an 110th LWP will fail. (If LWPs are given up, then subsequent requests will succeed, unless they would take the total number of LWPs across the task over 110.) The process.max-file-descriptor resource control is given no values. This means that processes entering this project will only have the system resource control value on this rctl. Example 2: Project Entry with Wildcards The following entries use wildcards: notroot:200:Shared Project:*,!root:: notused:300:Unused Project::!*: In this example, any user except "root" is a member of project "nonroot". For the project "notused", all groups are excluded. USAGE
The project database offers a reasonably flexible attribute mechanism in the final name-value pair field. Name-value pairs are separated from one another with the semicolon (;) character. The name is in turn distinguished from the (optional) value by the equals (=) character. The value field can contain multiple values separated by the comma (,) character, with grouping support (into further values lists) by parentheses. Each of these values can be composed of the upper and lower case alphabetic characters, the digits '0' through '9', and the punctuation characters hyphen (-), plus (+), period (.), slash (/), and underscore (_). Example resource control value specifications are provided in EXAMPLES, above, and in resource_controls(5) and getprojent(3PROJECT). SEE ALSO
newtask(1), projects(1), prctl(1), getprojent(3PROJECT), setrctl(2), unistd.h(3HEAD), nsswitch.conf(4), resource_controls(5) SunOS 5.10 1 Oct 2004 project(4)
All times are GMT -4. The time now is 11:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy