I have been able generate a file ($ELOG) that can have multiple lines within it. The first column represents the full path source file and the other is the full path target ... the file names are the same but the target directory paths are slightly different.
I need to run a 3rd party ENCRYPT (executable file) against <source_dir1>/file1 and then move it to <target_dir1/file1...<target_dir1>/file1 is the encrypted version of the human-readable <source_dir1>/file1
The code I have thusfar is
By using basename, I am hoping to seperate the filename so the line should read
ENCRYPT file1 <password> ....pause 3 and then move the file to the correct <target_dir> located in column 2 of the file
Unfortunately the baseline part is not working - what am I not doing correctly ?
First of all, you don't need to cat into a while, you can redirect the file into the while:
Further, the use of awk isn't needed either. Something like this should work, provided you actually can supply your encryption password as you indicated on the command line:
Last edited by agama; 11-13-2012 at 09:13 PM..
Reason: missing word
If your "ENCRYPT" command encrypts the file named by its 1st argument and stores the results in a file in the current directory with the same name, this should do what you want:
This is written using the Korn shell, but will work with any shell that accepts basic Bourne shell syntax (i.e., not csh or similar shells).
If you don't happen to be in the directory where the source file is located, passing the basename of the source file to ENCRYPT won't allow it to find your source file.
This User Gave Thanks to Don Cragun For This Post:
I've tried both and I think the one that I more readily understand and has worked all OK is your contribution Don
Agma - apologies but didn't understand <source##*/>....the ##* bit but I did appreciate you taking the time to explain that I didn't need cat / while
Hi davidra,
I'm glad to hear that my contribution worked for you.
This is what ${source##*/} does: it looks at the shell variable named source and if its value matches the pattern */ (which matches any string that ends with a / character), it removes the longest match for that pattern from the start (left) of the string. If $source does not contain any / characters, it is expanded unchanged. Similarly, ${var#pattern} removes the shortest match for pattern from the start of the expansion of $var, ${var%pattern} removes the shortest match for pattern from the end of the expansion of $var, and ${var%%pattern} removes the longest match for pattern from the end of the expansion of $var. For example:
produces the output:
This User Gave Thanks to Don Cragun For This Post:
Hi Guru's.
I am trying to use to check if $5 is greater than 80 & if not 100, then to print $0 :
awk '{ if ($5>80) && if ($5 != 100) print $0}
But getting error:
>bdf1|sed 's/%//g'|awk '{ if ($5>80) && if ($5 != 100) print $0}'
syntax error The source line is 1.
The error... (6 Replies)
I'm using solaris 10
Scenario as follows
I have a logfile with 2 columns:
column 1 = source directory + filename
column 2 = destination directory + filename
Using cron, my script polls for new files and adds them to the logfile ($ELOG) as described above. Using sed, the distination... (2 Replies)
Here is a very simple Korn shell script running on an AIX 5.3 box.
Why does this work without the $ prepended to RET_CD?
#!/bin/ksh
RET_CD=0
if &&
then
echo "RET_CD is not 0 and not 2"
else
echo "RET_CD is a 0 or a 2"
fi (3 Replies)
im trying to extract the basename of a process running on a host
processx is running at host1 as /applications/myapps/bin/processx
i wanted to check if its running, then extract the basename only using:
$ ssh host1 "ps aux | grep -v 'grep' | grep 'processx'" | awk '{ print basename $11}'
... (10 Replies)
Hi gurus,
i need your advise on how to process this file using awk.
i have this file
COLA COLB COLC COLD COLE COLF COLG COLH
AAAA 86 111 122 133 144 155 266 377
BBBB 70 211 222 233 244 255 266 ... (6 Replies)
I am having a hard time extracting the file name from the above code. Instead of printing /folder/file.1$.5$, I would like it to print the file name file.1$.5$.
I have tried using basename but it looks like NAWK or AWK does not recognise basename. Each time I type it in, it prints out the word... (4 Replies)
Hi Experts,
I am adding a column of numbers with awk , however not getting correct output:
# awk '{sum+=$1} END {print sum}' datafile
2.15291e+06
How can I getthe output like : 2152910
Thank you..
# awk '{sum+=$1} END {print sum}' datafile
2.15079e+06 (3 Replies)
hi if we have to use basename how can we do this in awk?
did the below but is not working..
psg -t "?"| awk '{
command=($5 ~ /^/)? $9:$8
# cmd_name=`basename $command` (gives error)
system("basename $command >>... (10 Replies)
Hi,
I am using the following command to extract any log files that are older than 3 days using the following command.
find DIR/LOGDIR -type f -mtime +3 |grep LOG > log_list.out
The results are
DIR/LOGDIR/1.LOG
DIR/LOGDIR/2.LOG
DIR/LOGDIR/3.LOG
DIR/LOGDIR/4.LOG
How do inculde (basename... (4 Replies)
The Web-based contact form on my site has been under distributed spamming attacks for nearly a month already. Obviously, a spammer has tried to generate HTTP requests containing ads to male drugs and all sorts of similar stuff directly to the form mail processor script on my site using a robot, as... (5 Replies)