[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

#DOES NOT WORK:  ls |  awk '{ split($1,array,"@") } {  system("cp "$1" "array[1]) }'

Posted on 2006-06-07
5
Medium Priority
?
532 Views
Last Modified: 2013-12-26
This doesn't work :-(  I'm trying to cp all files with @ in the name to a file name without the @.  (Note that all files in the directory structure have @1.1 at the end of the file name).

This will strip off the real filename:
ls | awk '{ split($1,array,"@") } {  print array[1] } '

but when I try to make the copy, it doesn't work?????

# ls |  awk '{ split($1,array,"@") } {  system("cp "$1" "array[1]) }'
# ls
DataNode.h@1.1         Makefile@1.1           parser.h@1.1
DataNodeFilter.h@1.1   MenuDataNodes.cc@1.1   parser.output@1.1
DataNodeVisitor.h@1.1  MenuDataNodes.h@1.1    parser.tab.c@1.1
getMenuFiles.cc@1.1    NodeLink.cc@1.1        parser.tab.h@1.1
getMenuFiles.h@1.1     NodeLink.h@1.1         scanner.h@1.1

Thanks, Allan

0
Comment
Question by:huffmana
  • 2
  • 2
5 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 16856887
#!/bin/sh
for i in *
do
   cp $i `echo $i|sed 's/@.*//'`
done
0
 

Author Comment

by:huffmana
ID: 16857079
Now how do I do this for a directory structure?

find . -type f | awk '{ split($1,array,"@") } {  system("cp "$1" "array[1]) }'

Thanks, Allan
0
 
LVL 48

Accepted Solution

by:
Tintin earned 2000 total points
ID: 16858461
#!/bin/sh
for i in `find /some/dir -type f`
do
  cp $i `echo $i|sed 's/@.*//'`
done
0
 

Author Comment

by:huffmana
ID: 16860568
Beautiful :-)  But not easy to remember.

Thanks, Allan
0
 
LVL 6

Expert Comment

by:JJSmith
ID: 16881573

adding @ to the find;

for i in `find /some/dir -type f -name "*@*"

would stop unecessary cp's and may stop the for in list buffer from blowing.

A more scalable approach would be;

find /some/dir -type f -name "*@*" | while read i
do
  cp $i `echo $i|sed 's/@.*//'`
done

Just an idea

Cheers
JJ
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…
Suggested Courses

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question