![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| jar command not being recognized | orahi001 | UNIX for Dummies Questions & Answers | 1 | 05-06-2008 07:29 AM |
| Retrieve 5th Field to Last Field !! | jobbyjoseph | UNIX for Dummies Questions & Answers | 3 | 05-16-2007 12:20 AM |
| Moving Part of a field to another field using AWK | rjsha1 | Shell Programming and Scripting | 5 | 08-04-2006 02:39 AM |
| I am not being recognized | Help | Forum Support Area for Unregistered Users & Account Problems | 0 | 01-10-2006 12:30 AM |
| Argument not recognized as integer | scmay | Shell Programming and Scripting | 1 | 05-13-2004 11:41 PM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hi,
I am writing a script to use awk to generate a set of cp commands from an input file abc. 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 script: $ cat abc | awk '{ print "cp -pr '`basename $1`' " $1 }' I tried to use awk with basename command, but it seems that the field $1 in backquotes is not recognized by awk. How to fix it? Many thanks, voa2mp3 |
| Forum Sponsor | ||
|
|
|
||||
|
Hi.
Quote:
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
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 |
|
||||
|
Some other ways
Code:
% set -- $(<file)
% paste -d" " <(printf "cp -pr %s\n" "${@##*/}") <(printf "%s\n" "$@")
cp -pr a.dbf /data/a.dbf
cp -pr b.dbf /data/june/b.dbf
Code:
zsh 4.3.4% <file while IFS= read;do print -r "cp -pr $REPLY:t $REPLY";done cp -pr a.dbf /data/a.dbf cp -pr b.dbf /data/june/b.dbf Code:
zsh 4.3.4% awk '$0="cp -pr "$NF" "$0' FS="/" file cp -pr a.dbf /data/a.dbf cp -pr b.dbf /data/june/b.dbf |
||||
| Google UNIX.COM |