This line looks dubious, because "ls <pattern>" uses a tabbed output with several columns, hence "wc -l" (count the lines) will presumably give the wrong result.
Either use "ls -1 *.dat" (which will output one file each line) or use "wc" (without the "-l" switch it will count "words" instead of "lines") in the line above. Preferably use "Z_FILE_COUNT=$(ls -1 *.dat | wc -l)" because this would cover for filenames containing blanks, which would otherwise confuse wc.
Hi all,
I would like to send the output of a line in a ksh script to a file, but I need to name the file using a predefined variable:
ls -l > $MYVAR.arc
But what is the correct syntax for achieving this? I can't seem to find the correct syntax for giving the file an extension.
Any... (8 Replies)
I am using a bash script to perform some automated maintenance on files in a directory. When I run the script using $sh -x script.sh <directory> the script works fine. It sets the variable to the oldest file, and continues on. However when I run the script like this $./script.sh <directory>, it... (5 Replies)
Hi,
I am trying to set a variable to be used in later scripting, and am having some difficulty. I want to look in a file called scan.info and find the line that says "variable ok". Then I want to cut the number at the beginning of that line and assign that number as a variable so that later... (4 Replies)
I suppose the easiest way to explain my problem is to show you some code and then show you what the code outputs:
--------------------------------------------------
#!/bin/bash
echo "This line has spaces" > "/tmp/This Filename Has Spaces.txt"
export Foo=$(cat "/tmp/This Filename Has... (4 Replies)
I've searched Google and now this forum. Best guess is my search fu is not good (and it probably isn't). The Google search did bring me here.
Background
I have a number of Korn Shell scripts who all use one of 3 values for an environment variable used in the backup system.
On occasion one or... (8 Replies)
I have a text file in which you need to identify the number of lines that looks like this:
awk '{x + +} END {print x}' filename
The problem is that I do not know how this data to any variable in which then need to continue to work in a cycle for ..
do not know someone help?
Sorry for my... (4 Replies)
If I have a txt file with
test.txt
somelineoftext
and I want to set that line of text to variable in a script:
so
#!/bin/bash
var=''
becomes
#!/bin/bash
var='somelineoftext' (3 Replies)
Hi All
I am checking for the presence of certain no of files in a directory. Only if the required no of files are present should I continue with my processing.
For e.g. in the temp directory below, there are 4 files of the format sample_aa(bb)(cc)(dd)_test. I need to check the count of these... (17 Replies)
Hi all, I have a file that contains characters. How do I get total of spesific character from that file and save the count to a variable for doing for calculation.
data.txt
1
2
2
2
2
3
3
4
5
6
7
8
5
4
3
4 (5 Replies)
I want to read properties from a file and print evaluated values of each key.
I am using AIX6.1.
myfile.props
protocol=http
siteA.host=siteAhostname
pageA=pageNameA
siteAURL1=${protocol}:/${siteA.host}/pagea/blabla?v1=32
siteAURL2=${protocol}:/${siteA.host}/${pageA}/blabla?v1=32... (5 Replies)