03-24-2013
@man:
You can use the index() function twice on $2 to determine the locations of the first "=" and ";". You can then use those indices to calculate the correct arguments for substr().
Regards,
Alister
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Sorry if this has been posted before, I searched but not sure what I really want to do.
I have a file with records that show who has logged into my application:
2003-03-14:I:root: Log_mesg: registered servername:userid. (more after this)
I want to pull out the userid, date and time into... (2 Replies)
Discussion started by: MizzGail
2 Replies
2. Shell Programming and Scripting
Hi all,
I have a flatfile
I would like to get ext = 7950 , how do I do that ?
if ($1 == "CTI-ProgramStart") {
ext = substr($9,index($9,"Extension")+11,4);
But why it is not working ???? Please help .
Thanks (1 Reply)
Discussion started by: sabercats
1 Replies
3. UNIX for Dummies Questions & Answers
i have a variable 200612
the last two digits of this variable should be between 1 and 12, it should not be greater than 12 or less than 1 (for ex: 00 or 13,14,15 is not accepted)
how do i check for this conditions in a unix shell script.
thanks
Ram (3 Replies)
Discussion started by: ramky79
3 Replies
4. Shell Programming and Scripting
Hi
I have multiple files that name begins bidb_yyyymm. (yyyymm = current year month of file creation).
What I want to do is look at the files and where yyyymm is older than 1 month I want to remove the file from the server.
I was looking at looping through the files and getting the yyyymm... (2 Replies)
Discussion started by: colesga
2 Replies
5. UNIX for Dummies Questions & Answers
I have a variable '$test' that has the following string value:
$test = 123|456|789|0123
How would I select just the first element ('123') using awk.
Note: '|' is the delimiter, and the length of each field can vary.
Thanks,
- CB (3 Replies)
Discussion started by: ChicagoBlues
3 Replies
6. Shell Programming and Scripting
I have the following to find lines matching "COMPLETE" and extract parts of it using substr.
sed -n "/COMPLETE/p" 1.txt | awk 'BEGIN { FS = "\" } {printf"%s %s:%s \n", substr($3,17,3),substr($6,4,1), substr($7,4,1)}' | sort | uniq > temp.txt
Worked fine until the numbers in 2nd & 3rd substr... (5 Replies)
Discussion started by: zpn
5 Replies
7. Shell Programming and Scripting
HI I am using awk and substr function to list out the directory names in the present working directory .
I am using below code
ls -l | awk '{ if ((substr($1,1,1)) -eq d) {print $9 }}'
But the problem is i am getting all the files and directories listed where as the requirement i wrote... (7 Replies)
Discussion started by: prabhu_kumar
7 Replies
8. Shell Programming and Scripting
Hi to all,
I'm here again, cause I need your help to solve another issue for me.
I have some files that have this name format: date_filename.csv
In my shell I must rename each file removing the date so that the file name is filename.csv
To do this I use this command:
fnames=`ls ${fname}|... (2 Replies)
Discussion started by: leobdj
2 Replies
9. Shell Programming and Scripting
Hi,
- In a file test.wmi
Col1 | firstName | lastName
4003 | toto_titi_CT- | otot_itit
- I want to have only ( colones $7,$13 and $15) with code 4003 and 4002. for colone $13 I want to have the whole name untill _CT- or _GC-
1- I used the command egrep with awk
#egrep -i... (2 Replies)
Discussion started by: georg2014
2 Replies
10. Shell Programming and Scripting
Hello All;
I have an input file 'abc.txt' with below text:
512345977,213458,100021
512345978,213454,100031
512345979,213452,100051
512345980,213455,100061
512345981,213456,100071
512345982,213456,100091
512345983,213457,100041
512345984,213451,100011
I need to paste the first field... (10 Replies)
Discussion started by: mystition
10 Replies
arybase(3pm) Perl Programmers Reference Guide arybase(3pm)
NAME
arybase - Set indexing base via $[
SYNOPSIS
$[ = 1;
@a = qw(Sun Mon Tue Wed Thu Fri Sat);
print $a[3], "
"; # prints Tue
DESCRIPTION
This module implements Perl's $[ variable. You should not use it directly.
Assigning to $[ has the compile-time effect of making the assigned value, converted to an integer, the index of the first element in an
array and the first character in a substring, within the enclosing lexical scope.
It can be written with or without "local":
$[ = 1;
local $[ = 1;
It only works if the assignment can be detected at compile time and the value assigned is constant.
It affects the following operations:
$array[$element]
@array[@slice]
$#array
(list())[$slice]
splice @array, $index, ...
each @array
keys @array
index $string, $substring # return value is affected
pos $string
substr $string, $offset, ...
As with the default base of 0, negative bases count from the end of the array or string, starting with -1. If $[ is a positive integer,
indices from "$[-1" to 0 also count from the end. If $[ is negative (why would you do that, though?), indices from $[ to 0 count from the
beginning of the string, but indices below $[ count from the end of the string as though the base were 0.
Prior to Perl 5.16, indices from 0 to "$[-1" inclusive, for positive values of $[, behaved differently for different operations; negative
indices equal to or greater than a negative $[ likewise behaved inconsistently.
HISTORY
Before Perl 5, $[ was a global variable that affected all array indices and string offsets.
Starting with Perl 5, it became a file-scoped compile-time directive, which could be made lexically-scoped with "local". "File-scoped"
means that the $[ assignment could leak out of the block in which occurred:
{
$[ = 1;
# ... array base is 1 here ...
}
# ... still 1, but not in other files ...
In Perl 5.10, it became strictly lexical. The file-scoped behaviour was removed (perhaps inadvertently, but what's done is done).
In Perl 5.16, the implementation was moved into this module, and out of the Perl core. The erratic behaviour that occurred with indices
between -1 and $[ was made consistent between operations, and, for negative bases, indices from $[ to -1 inclusive were made consistent
between operations.
BUGS
Error messages that mention array indices use the 0-based index.
"keys $arrayref" and "each $arrayref" do not respect the current value of $[.
SEE ALSO
"$[" in perlvar, Array::Base and String::Base.
perl v5.16.2 2012-10-11 arybase(3pm)