Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-18-2010, 05:43 AM   #1
Registered: Mar 2008
Location: Bangalore
Distribution: Enterprise Red Hat linux
Posts: 98

Rep: Reputation: 16
Smile Copy when you condition meet !!

In one file i am having list of files from one directory, i want to copy it to some other directory .

$cat test.txt
mno.txt 2
pqr.gif  3
uvx.xml 7
abc.txt  1
I want to copy this files where the 2nd field is less then 5. So here i want only to copy mno.txt , pqr.gig, abc.txt to some other directory.Not the uvx.xml cause it's value is more then 5.

How can i do in awk using array.
Old 03-18-2010, 05:53 AM   #2
Registered: Feb 2010
Distribution: gentoo, arch, fedora, freebsd
Posts: 379

Rep: Reputation: 97
FILES=`cat test.txt | awk '{if ($2<5) print $1}'`
for FILE in $FILES
  cp /source_dir/$FILE /dest_dir2/

Last edited by troop; 03-18-2010 at 05:55 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Condition Variables 2184ast Linux - General 0 02-21-2009 02:31 PM
if condition furqan_sindhu Linux - Newbie 5 09-22-2007 07:56 AM
using OR condition in if condition Fond_of_Opensource Linux - Newbie 2 10-20-2006 01:34 AM
cedega and CS: condition zero bojann Linux - Games 8 06-27-2005 02:49 PM
CounterSrike: Condition Zero Comarez Linux - Games 2 04-20-2004 03:08 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:02 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration