06-14-2005
apologies
Ah yes, of course. Let me type out the larger picture so you can see how it's working.
The ls.txt is a cut listing of filenames (one filename per line).
As I'm opening each file, which happen to be all fixed-length csv files, I'm cutting the first field and the fifth field.
The following would be an example of two records (each line in each fixed-length csv file is a record with aproximately 32 fields). I have isolated the two fields for you.
Example fields (the forum deletes extra spaces so it would be easier I think if I describe it instead: FIELD1 is in columns 2-4 (a string of 3 letters), and the the second column aka FIELD5 can either be filled with a one digit number (1-9) or a single space (" ").
PHP Code:
while read FILENAME; do
FIELD1=`cut -c2-5 $FILENAME`
FIELD5=`cut -c68 $FILENAME`
if [ $FIELD1 -eq "PBR" && $FIELD5 -eq " " ]; then
$count++
fi
done < ls.txt
I'm kind of thinking that maybe it's not working because... if you try to use the "cut" command and it cuts a single space, maybe the shell doesn't assign anything to the variable?
Last edited by yongho; 06-14-2005 at 11:29 AM..
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi All,
Can some one tell me how to get run the following:
data1="hello"
data2="world"
if
then
{
echo "good afternnon"
}
else
{
echo " good morning"
}
fi
The above code gives me an error ad below :
./if.h: line 3: ' (7 Replies)
Discussion started by: jisha
7 Replies
2. Shell Programming and Scripting
VARIABLE="project"
if && ]
then
echo "VARIABLE is not empty"
fi
this is not working what is wrong in the syntax?? (2 Replies)
Discussion started by: codeman007
2 Replies
3. Shell Programming and Scripting
Hi, I hope the title does not scare people to look into this thread but it describes roughly what I'm trying to do. I need a solution in PHP.
I'm a programming beginner, so it might be that the approach to solve this, might be easier to solve with an other approach of someone else, so if you... (0 Replies)
Discussion started by: lowmaster
0 Replies
4. Programming
Hello there,
My first time on the forums, glad to be here :)
I'm completely new to programming in PHP and I have a question which I hope someone could help me with.
I am currently using this statement:
if(($session == 2) && ($item == Dagger) && ($item2 == Dagger)){
... (5 Replies)
Discussion started by: Hero
5 Replies
5. Shell Programming and Scripting
Hi
What is the syntax for if statement using && and || operator?
if && ] ||
here its giving me an error to this if statement
any suggestion?? (2 Replies)
Discussion started by: Avi
2 Replies
6. Shell Programming and Scripting
Hi, I'm using the && operator in if statement:
if ; then
exp $UID/$PWD@$ORACLE_SID FILE=./DUMP/$TODAY$CONCAT_STR$USERNAME.dmp STATISTICS=NONE LOG=./LOG/$TODAY$CONCAT_STR$USERNAME.log
elif ; then
expdp $UID/$PWD@$ORACLE_SID DIRECTORY=./DUMP/ DUMPFILE=$TODAY$CONCAT_STR$USERNAME.dmp... (8 Replies)
Discussion started by: priya001
8 Replies
7. Shell Programming and Scripting
how do you write an if statement for something like
if ((expr 1 >= expr 2 && expr 3 >= expr 4) && expr 5 <= expr 6)
if ((TRUE && TRUE) && TRUE) then
condition...
i've done it this way but it doesn't seem to work.
if (] && "$ex_day" -le "$curr_day" ); then
condition... (3 Replies)
Discussion started by: angilulu
3 Replies
8. Shell Programming and Scripting
Firstly, I would like to apologize if this is not the appropriate sub-forum to post about GNU/BSD makefile scripting. Though my code is in C++, because I am focusing on the makefile I thought it would go better in shell scripting. Please correct me if I am wrong.
Secondly, I am not interested in... (0 Replies)
Discussion started by: AntumDeluge
0 Replies
9. Shell Programming and Scripting
Hi All,
Do you have any sample script,
- auto get file from SFTP remote server and delete file in remove server after downloaded.
- only download specify filename
- auto upload file from local to SFTP remote server and delete local folder file after uploaded
- only upload specify filename
... (3 Replies)
Discussion started by: weesiong
3 Replies
10. Shell Programming and Scripting
Hello,
Below I try to control that the input is good an IP :
#!/bin/bash
cp /home/scripts/choice_interfaces.txt /home/scripts/interfaces.txt
chmod 644 /home/scripts/interfaces.txt
echo -e "Please enter the network informations into the /etc/network/interfaces file, complete them below... (9 Replies)
Discussion started by: Arnaudh78
9 Replies
LEARN ABOUT OPENDARWIN
cut
CUT(1) BSD General Commands Manual CUT(1)
NAME
cut -- select portions of each line of a file
SYNOPSIS
cut -b list [-n] [file ...]
cut -c list [file ...]
cut -f list [-d delim] [-s] [file ...]
DESCRIPTION
The cut utility selects portions of each line (as specified by list) from each file and writes them to the standard output. If no file argu-
ments are specified, or a file argument is a single dash ('-'), cut reads from from the standard input. The items specified by list can be
in terms of column position or in terms of fields delimited by a special character. Column numbering starts from 1.
The list option argument is a comma or whitespace separated set of increasing numbers and/or number ranges. Number ranges consist of a num-
ber, a dash ('-'), and a second number and select the fields or columns from the first number to the second, inclusive. Numbers or number
ranges may be preceded by a dash, which selects all fields or columns from 1 to the first number. Numbers or number ranges may be followed
by a dash, which selects all fields or columns from the last number to the end of the line. Numbers and number ranges may be repeated, over-
lapping, and in any order. It is not an error to select fields or columns not present in the input line.
The options are as follows:
-b list
The list specifies byte positions.
-c list
The list specifies character positions.
-d delim
Use the first character of delim as the field delimiter character instead of the tab character.
-f list
The list specifies fields, delimited in the input by a single tab character. Output fields are separated by a single tab character.
-n Do not split multi-byte characters.
-s Suppress lines with no field delimiter characters. Unless specified, lines with no delimiters are passed through unmodified.
ENVIRONMENT
The LANG, LC_ALL and LC_CTYPE environment variables affect the execution of cut if the -n option is specified. Their effect is described in
environ(7).
EXAMPLES
Extract users' login names and shells from the system passwd(5) file as ``name:shell'' pairs:
cut -d : -f 1,7 /etc/passwd
Show the names and login times of the currently logged in users:
who | cut -c 1-16,26-38
DIAGNOSTICS
The cut utility exits 0 on success, and >0 if an error occurs.
SEE ALSO
paste(1)
STANDARDS
The cut utility conforms to IEEE Std 1003.2-1992 (``POSIX.2'').
HISTORY
A cut command appeared in AT&T System III UNIX.
BUGS
The -c option is a synonym for the -b option, which causes incorrect behaviour in locales that support multibyte characters.
When operating on fields (-f option is specified), cut does not recognise multibyte characters, and the delim character is recognised in the
middle of multibyte sequences.
BSD
June 6, 1993 BSD