The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 10-07-2007
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 712
Hi.
Quote:
Originally Posted by voa2mp3 View Post
...
file abc:
/data/a.dbf
/data/june/b.dbf

desired output:
cp -pr a.dbf /data/a.dbf
cp -pr b.dbf /data/june/b.dbf
...
Placing the input on fille "data1", and changing your script slightly to:
Code:
#!/usr/bin/env sh

# @(#) a1       Demonstrate awk feature "command | getline".

set -o nounset
echo

## Use local command version for the commands in this demonstration.

echo "(Versions of codes used in this script -- local code \"version\")"
version bash awk

echo

awk '
        { command = "basename " $1
        command | getline file
        print "cp -pr " file " " $1 }
' data1

exit 0
produces:
Code:
% ./a1

(Versions of codes used in this script -- local code "version")
GNU bash, version 2.05b.0(1)-release (i386-pc-linux-gnu)
GNU Awk 3.1.4

cp -pr a.dbf /data/a.dbf
cp -pr b.dbf /data/june/b.dbf
cheers, drl