The UNIX and Linux Forums  
Hallo und herzlich Willkommen aus den Vereinigten Staaten, die UNIX-und Linux-Foren! Vielen Dank für Ihren Besuch und die Teilnahme an unserem Global Community.

Go Back   Die UNIX-und Linux-Foren > Top Foren > UNIX for Dummies Questions & Answers
.
Google unix.com



UNIX for Dummies Questions & Answers Wenn Sie nicht sicher sind, wo Sie eine UNIX-oder Linux-Frage, post it here. Alle UNIX-und Linux-Anfänger willkommen!

Mehr UNIX-und Linux-Forum Themen Vielleicht finden Sie hilfreiche
Faden Thread Starter Forum Antworten Last Post
jar-Befehl nicht erkannt orahi001 UNIX for Dummies Questions & Answers 1 05-06-2008 11:29 AM
Abrufen 5. Letzte Feld zu Feld! jobbyjoseph UNIX for Dummies Questions & Answers 3 05-16-2007 04:20 AM
Beweglicher Teil eines Feldes zu einem anderen Feld mit AWK rjsha1 Shell Programmierung und Scripting 5 08-04-2006 06:39 AM
Ich bin nicht erkannt Hilfe Forum Support-Bereich für Besucher & Account Probleme 0 01-10-2006 04:30 AM
Argument nicht als integer scmay Shell Programmierung und Scripting 1 05-14-2004 03:41 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Suche diesen Thread Rate Thread Anzeige-Modi
  #1 (permalink)  
Old 10-07-2007
voa2mp3 voa2mp3 is offline
Registrierte Nutzer
  
 

Join Date: Oct 2007
Beiträge: 3
Post awk Bereich nicht in backquotes

Hi,

Ich schreibe ein Skript zu verwenden awk, um eine Reihe von CP-Kommandos aus einer Eingabedatei ABC.

abc-Datei:
/ data / a.dbf
/ data / Juni / b.dbf

gewünschte Ausgabe:
cp --pr a.dbf / data / a.dbf
cp --pr b.dbf / data / Juni / b.dbf

Skript:
$ Cat abc | awk '(print "cp --pr "` basename $ 1 `" "$ 1) '

Ich habe versucht, mit Einsatz awk basename Befehl, aber es scheint, dass das Feld $ 1 in backquotes wird nicht erkannt von awk. Wie man dies beheben kann?

Vielen Dank,
voa2mp3
  #2 (permalink)  
Old 10-07-2007
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registriert Geek
  
 

Join Date: Dezember 2003
Ort: Melbourne, Australien
Beiträge: 2.100
Ein paar Lösungen

awk:
Code:
$ awk '{s=$0;gsub( /^.*\//, "" );printf("cp -pr %s %s\n", $0, s )}' abc
cp -pr a.dbf /data/a.dbf
cp -pr b.dbf /data/june/b.dbf
sed:
Code:
$ sed 's!^\(.*\)/\(.*\)!cp -pr \2 \1/\2!' abc 
cp -pr a.dbf /data/a.dbf
cp -pr b.dbf /data/june/b.dbf
bash / ksh:
Code:
$ while read file; do echo "cp -pr ${file##*/} ${file}"; done < abc 
cp -pr a.dbf /data/a.dbf
cp -pr b.dbf /data/june/b.dbf
  #3 (permalink)  
Old 10-07-2007
voa2mp3 voa2mp3 is offline
Registrierte Nutzer
  
 

Join Date: Oct 2007
Beiträge: 3
Hi zazzybob,

Vielen Dank, dass Sie mir helfen.

voa2mp3
  #4 (permalink)  
Old 10-07-2007
drl's Avatar
DRL drl is online now Forum Advisor  
Registrierte Nutzer
  
 

Join Date: Apr 2007
Ort: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Beiträge: 711
Hi.
Zitat:
Zitat von voa2mp3 View Post
...
abc-Datei:
/ data / a.dbf
/ data / Juni / b.dbf

gewünschte Ausgabe:
cp --pr a.dbf / data / a.dbf
cp --pr b.dbf / data / Juni / b.dbf
...
Wenn man den Eingang fille "data1", und ändern Sie Ihre Skript leicht zu:
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
produziert:
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
  #5 (permalink)  
Old 10-07-2007
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Lage: Варна, България / Milano, Italia
Posts: 2876
Einige andere Arten

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
und mit zsh:

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
oder awk:

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
Closed Thread

Lesezeichen

Tags
Linux-Befehle

Thread Tools Suche diesen Thread
Suche diesen Thread:

Erweiterte Suche
Anzeige-Modi Rate this thread
Rate this thread:

Forumregeln
Du möglicherweise nicht neue Themen
Du möglicherweise nicht nach Antworten
Du möglicherweise nicht post-Anlagen
Du möglicherweise nicht bearbeiten Sie Ihre Beiträge

BB-Code ist Auf
Smilies sind Auf
[IMG] Code Auf
HTML-Code ist Aus
Trackbacks sind Auf
Pingbacks sind Auf
Refbacks sind Auf




Alle Zeiten sind GMT -4. Es ist jetzt 08:11 AM.


Powered by: vBulletin, Copyright © 2000 - 2006, Jelsoft Enterprises Ltd. Sprachliche Übersetzungen Powered by .
vBCredits v1.4 Copyright © 2007 - 2008, PixelFX Studios
Die UNIX-und Linux-Foren Content © Copyright 1993-2009. Alle Rechte Reserved.Ad Management von RedTyger

Content Relevant URLs durch vBSEO 3.2.0