- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- scripting - awk
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2003 07:14 AM
04-14-2003 07:14 AM
I'm new to scripting and have simple question about a script I'm trying to do, wonder if someone can help?
The script creates a temporary file containing a list of files I'm interested in, what I now want the script to do is mv those files to a different directory. I'm sure it's easy but I can't get my head around it!
I've been trying with the following loop but no result:
for i in `cat $LISTFILE | awk `{print $1}``
do cp $i $OUTDIR
done
Can anyone see the problem or suggest something more elegant (but simple please!)
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2003 07:20 AM
04-14-2003 07:20 AM
Re: scripting - awk
# define LISTFILE and OUTDIR
LISTFILE=/tmp/abc.txt
OUTDIR=/target_dir
for file in `cat $LISTFILE | awk '{print $1}'` # notice presence of both grave accent and single quotes here
do
cp $i $OUTDIR
done
<<<<<<<<<<
should work fine now.
- ramd.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2003 07:20 AM
04-14-2003 07:20 AM
SolutionHere is one way to do it:
for i in $(awk '{print $1}' $LISTFILE);
do
cp $i $OUTDIR
done
The $() executes a command just like the back ticks do.
If your LISTFILE just contains the file names and no other fields, you could do the for line like this:
for i in $(<$LISTFILE)
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2003 07:21 AM
04-14-2003 07:21 AM
Re: scripting - awk
cd fromdirectory
cat $LISTFILE | cpio -pd $OUTDIR
Do a "man cpio" to see if it can be used for your task.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2003 07:23 AM
04-14-2003 07:23 AM
Re: scripting - awk
- ramd.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2003 07:24 AM
04-14-2003 07:24 AM
Re: scripting - awk
Make sure LISTFILE and OUTDIR are defined. Also if the filenames are single names I will take the awk command out.
DR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2003 07:37 AM
04-14-2003 07:37 AM
Re: scripting - awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2003 02:39 PM
04-14-2003 02:39 PM
Re: scripting - awk
safe_copy()
{
for i in $(awk '{print $1}' $LISTFILE);
do
cp $i $OUTDIR
if [ $? = 0 ]
then
printf "$i copied succesfully to $OUTDIR\n"
else
printf "$i failed to copy\n"
fi
done
}
email_results()
{
SUBJECT=$*
USERS="youremailaddress@where-ever.net"
mailx -s "${SUBJECT}" $USERS <${OUTFILE}
}
cleanup()
{
rm /tmp/$$.tmp
}
#
# Main
#
trap 'cleanup' 0
OUTDIR=
LISTFILE=
OUTFILE=$$.tmp
save_copy | tee -a $OUTFILE
email_results
exit 0
___END___
enjoy the freedom of ITRC
peace
Donny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2003 02:59 PM
04-14-2003 02:59 PM
Re: scripting - awk
Thanks
Zafar