The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Comparing files enen when they are not in order ragavhere Shell Programming and Scripting 2 06-04-2008 05:13 PM
Order files by create date mab_arif16 Shell Programming and Scripting 4 05-15-2006 01:04 PM
Adding files of numerical data Boucho High Level Programming 17 02-07-2006 04:29 PM
lp - order of files printed mabrownawa UNIX for Advanced & Expert Users 2 02-16-2004 12:08 PM
Recursive directory listing without listing files psingh UNIX for Dummies Questions & Answers 4 05-10-2002 10:52 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-22-2005
Steve_H Steve_H is offline
Registered User
  
 

Join Date: Feb 2005
Location: UK
Posts: 6
Listing files in numerical order

Hi, I'm trying to write a ksh script to copy a specified number of files from one directory to another.

The files are named in the convention <switchname>_log.<num> and the numbers are sequential single digit onwards. I figured I could find some parameter for ls which would list the files in correct order but having searched high and low i cannot figure this one out.

I consistently get -

<switchname>_log.1
<switchname>_log.10
<switchname>_log.11
<switchname>_log.12
<switchname>_log.13
<switchname>_log.14
<switchname>_log.15
<switchname>_log.16
<switchname>_log.17
<switchname>_log.18
<switchname>_log.19
<switchname>_log.2
<switchname>_log.20

etc.

I want to do a couple of things - firstly I want to write a script which moves the first numerically sequenced file from the directory, I will then put this in some sort of loop so it does it every 5 minutes for each of 12 directories.

Secondly I want to to be able to do this as a one off taking the first X number of each switch's files to copy elsewhere.

HELP PLEASE!
  #2 (permalink)  
Old 02-22-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
something to start with:
Code:
#!/bin/ksh

ls *_log.*([0-9]*) | nawk -F'.' '{print $NF, $0}' | sort -n | cut -d ' ' -f2-
  #3 (permalink)  
Old 02-22-2005
Steve_H Steve_H is offline
Registered User
  
 

Join Date: Feb 2005
Location: UK
Posts: 6
Thanks, that gives me the listing I want.

How do I now grab the first list element (or the first X list elements) and cp it/them out?
  #4 (permalink)  
Old 02-22-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Quote:
Originally Posted by Steve_H
Thanks, that gives me the listing I want.

How do I now grab the first list element (or the first X list elements) and cp it/them out?
and here's something to start with:
Code:
#!/bin/ksh
for iter in $(ls *_log.*([0-9]*) | sed -e 's#^\([^_][^_]*\).*#\1#g'|sort -u)
do
   echo ${iter}
done
you can experiment with this and with the previous posting.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:47 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0