1833405 Members
2890 Online
110052 Solutions
New Discussion

Help with script

 
SOLVED
Go to solution
Ricardo Bassoi
Regular Advisor

Help with script


Hi all,

In the script attached the var USER contain no data, maybe its a problem while reading the data.txt.
Anybody can help ?
If you never try, never will work
13 REPLIES 13
curt larson_1
Honored Contributor

Re: Help with script

could you provide the contents of the file data.txt?
Con O'Kelly
Honored Contributor

Re: Help with script

Hi Ricardo

Your syntax looks correct to me.
What value is contained in the $USER_ASS variable prior to:
USER=`echo $USER_ASS|awk -F "-" '{print $1}'`

One thing that is possible is that the first field of the $USER_ASS has a "-". If this is the case you'll get nothing returned.

Also check further up, what's in data.txt??

Cheers
Con
Ricardo Bassoi
Regular Advisor

Re: Help with script


Hi,


Sorry !

The data.txt contains:

91838383;23/05/2003
91834383;22/07/2003
91838563;23/05/2003
91838383;03/09/2003
91838383;13/01/2003
34838383;23/05/2003
54838383;23/05/2003
91838381;25/12/2002

If you never try, never will work
Ricardo Bassoi
Regular Advisor

Re: Help with script


Sorry again,

The correct is:

91838383-23/05/2003
91834383-22/07/2003
91838563-23/05/2003
91838383-03/09/2003
91838383-13/01/2003
34838383-23/05/2003
54838383-23/05/2003
91838381-25/12/2002
If you never try, never will work
Con O'Kelly
Honored Contributor

Re: Help with script

The "while read DATA USER" line only sees one field in this file.
It reads everything into DATA variable, the USER_ASS is empty.
Hence when you run
USER=`echo $USER_ASS|awk -F "-" '{print $1}'`
the $USER_ASS Variable is empty.

You need to insert a space before or after ";" in the data.txt file and it will work.

Cheers
Con

Con O'Kelly
Honored Contributor

Re: Help with script

Sorry should have said a space before or after "-" (not ";") in the data.txt file.

Cheers
Con
Con O'Kelly
Honored Contributor

Re: Help with script

Hi Ricardo(again)

Change the line
awk -F ";" '{printf "%-9s-%-10s\n",$1,$2}' temp.txt > data.txt
to
awk -F ";" '{print $1, $2}' temp.txt > data.txt

This should fix your problem.

Cheers
Con
curt larson_1
Honored Contributor

Re: Help with script

modify

cat data.txt | while read DATA USER_ASS
do
USER=`echo $USER_ASS|awk -F "-" '{print $1}'`
DATA_SISTEMA=`echo $DATA|awk -F "-" '{print $2}'`


to be:

cat data.txt | while read DATA
do
USER=${DATA%%-*}
DATA_SISTEMA=${DATA#*-}
Con O'Kelly
Honored Contributor

Re: Help with script

Sorry for all the multiple posts - please zero point them all.

Looked again at my previous post & realised you're using "-" as a field seperator, therefore the variable assignments for USER & DATA_SISTEMA do not need the '-F "-"' as part of the awk (white space is a default).

Cheers
Con
Ricardo Bassoi
Regular Advisor

Re: Help with script


Corn,

How to remove the / in the DATA and do the compare ?

Curtis,

Can you explain:

USER=${DATA%%-*}
DATA_SISTEMA=${DATA#*-}

Tks
If you never try, never will work
Con O'Kelly
Honored Contributor
Solution

Re: Help with script

Hi Ricardo

No points please.
Just a few ideas - I haven't tested any of this so might be wrong as before!!
I think you're talking about comparing the dates at the end of your script??
You can amend your script as:

......
#---echo $DATA
DATA_ATUAL=`date +%Y%m%d`
DATA_SISTEMA=`echo $DATA_SISTEMA |awk -F/ '{print $3$2$1}'`
if [ $DATA_ATUAL -gt $DATA_SISTEMA]
......

No need for the lines:
DATA2=`date +%d/%m/%Y`
#---echo $DATA2

Not sure if thats what you're after.

Cheers
Con

Ricardo Bassoi
Regular Advisor

Re: Help with script


Sorry Corn,

But you deserves it !!!

Tks
If you never try, never will work
curt larson_1
Honored Contributor

Re: Help with script

# input the whole line into the variable DATA
#
cat data.txt | while read DATA
do

# this is parameter expansion using substrings
#
# %% removes the large right pattern
# syntax is ${param%%pattern}
# example
# x=foo/fun/bar
# print ${x%%/*}
# foo
#
# # removes the small left pattern
# syntax is ${param#pattern}
# example
# cd $HOME/src/cmd
# print ${PWD#$HOME/}
# src/cmd
#
# USER = DATA with all characters removed from the right up to and including the first -, i.e. everything before the first -
#
# DATA_SISTEMA = DATA with all characters removed from the left up to and including the first -, i.e. everything after the first -
#
#
USER=${DATA%%-*}
DATA_SISTEMA=${DATA#*-}