Counting items in variables, How come this works, However
Hi All,
To start with, I have been reading this site for years, Unfortunately I do not consider myself versed well enough with scripts to provide useful help to others. The Blind cannot lead the Blind!
Many of you have provided me with brain food and solutions over the years without even knowing it and for that... I thank you, for doing what you do!
Now my question is ...
WHY does the following work, It Prepends a valid ITEMCOUNT to each lineitem, yet
prints 0 (Zero)!
It's because ITEMCOUNT is only defined in the while loop. Try this:
Awesome ... Beautiful ... Cool ... etc...
Of course the first thing I did was reformat it like...
NOTICE the spaces to the left of...
after I put it back to YOUR EXACT formating it worked as expected.
However I'm not sure I understand it!
This is what I get: "eofITEMLISTeof" is redirected to read.
Is that correct??
As for it only being defined in the loop, is beyond me, I see it as it was defined above the function.
The only difference I see is how the read is fed...
Also can it be re-formated any other way? like maybe...
I really don't want it hanging around on the left margin, makes for messy reading.
Thanks Mucho peterro
-Enjoy
fh : )_~
---------- Post updated at 06:18 PM ---------- Previous update was at 06:08 PM ----------
Quote:
Originally Posted by mglenney
Maybe I'm not reading this correctly but you could get the number of items in the array this way:
I need the count of elements (positional parameters), the above is the total byte count of ITEMLIST.
According to FBSD7.1R Man page the following expands to the number of positional parameters!
However I have been unable to get it to output anything other than 1.
That was the very first thing I tried.
Speaking of total byte count... whats MAX for bytes in a variable as such.
Thanks for your input!
-Enjoy
fh : )_~
---------- Post updated at 07:08 PM ---------- Previous update was at 06:18 PM ----------
peterro,
I just found an issue with code:
It includes the echo and double quote at the head of the first ITEM and a double quote at the tail of the last ITEM.
The following fix seems to work?
Removal of echo and double quotes.
Not sure about the quote issue, but I do understand the messy formatting. You could put a dash "-" in the start of the here document like this:
This allows for better formatting although I think the final EOF still needs to be at the beginning of the line. I suspect you're using since it is behaving like this. More info can be found in Chapter 10 of Expert Shell Scripting (Apress).
Hey everyone,
I have a bunch of lines with values in field 4 that I am interested in.
If these values are between 1 and 3 I want it to count all these values to all be counted together and then have the computer print out
LOW and the number of lines with those values in between 1 and 3,... (2 Replies)
Hi,
Let's I have the following strings (md5):
07177edf8261d28c6a003e583fcbe38c
0717c0037b3a20fc0f0998e673f228d5
0717d611a5d24374628b98e17fd00977,0717d611a5d24374628b98e17fd00977
07189a18afdae558bb5aadfe602e4a91
0719e97d481c239667f38a3e166bed74
071af3225fe50a1fdbb42c43aac313cc... (4 Replies)
Hello, I'm writing a script in sh in which the first command line argument is a directory. from that, i'm suppose to count the number of readable, writable, and executable items in the directory. I know using $1 represents the directory, and ls would display all the items in the directory, and that... (4 Replies)
Hi everyone.
I have a lot of programs i want to run on some data files, they need to be done sequentially. Often the output from one program is the input for the next.
e.g
$ progA data1 > data1.A
$ progB data1.A > data1.AB
$ progC data1.AB > data1.ABC
repeat on data2, 3, 4, 5, 6 etc
... (4 Replies)
Hi,
I've a list in the following format:
Empdept filedetails buildingNo Area
AAA 444 2 juy
AAA 544 2 kui
AAA 567 4 poi
AAA 734 5 oiu
AAA 444 ... (2 Replies)
Hi,
I'm a complete newbie so bear with me.
I have a directory (and sub-dirs) full of .doc, .xls files.
What I'm trying to do is do a single search within the files (i.e. within each .doc etc) for occurrences of multiple items e.g. apples, pears, grapes, bananas.
Basically I'd provide a... (4 Replies)
This should be so simple.. I have folder with about 27 subfolders in it, each folder has a number of fonts in it.. how do I get the total number of fonts for all subfolders? (2 Replies)
OS=HP-UX ksh
The following works, except I want to include the <start> and <end> in the output.
awk -F '<start>' 'BEGIN{RS="<end>"; OFS="\n"; ORS=""} {print $2} somefile.log'
The following work in bash but not in ksh
sed -n '/^<start>/,/^<end>/{/LABEL$/!p}' somefile.log (4 Replies)
Hi,
I have 2 files with contents in them and I need to compare each item in each file.
File1:
item4
item5
File2:
item2
item3
item5
item6
The items names can be of different lengths.
If the items in the File1 are not in File2,
delete the missing item in File1.
The resulting... (12 Replies)