Sponsored Content
Top Forums Shell Programming and Scripting Sequential numbering from 1 to ten Post 302890158 by Chubler_XL on Tuesday 25th of February 2014 12:07:30 PM
Old 02-25-2014
This version shuffles the existing files down and places new file at #1 (deleting old #10).

Code:
#!/bin/bash

mv_down() {
   rm -f 10_*
   for ((i=9; i ; i--)) {
       printf -v FILE "%s" ${i}_*
       [ -f "$FILE" ] || continue
       BASE=${FILE#${i}_}
       mv -f "$FILE" "$((i+1))_$BASE"
   }
   mv "$1" "1_$1"
}

cd folder
while true
do
    for file in *
    do
       [[ ! -f "$file" || "$file" = [1-9]_* || "$file" = 10_* ]] && continue
       mv_down "$file"
    done
    sleep 1
done


Last edited by Chubler_XL; 02-25-2014 at 02:40 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

numbering of process

:confused: How does UNIX handle the numbering of processes? (2 Replies)
Discussion started by: tweety111
2 Replies

2. UNIX for Dummies Questions & Answers

Numbering!

Just a shot question... how to make 1,2,3,...999 into the form of 001,002,003....999 (3 digits) Thanks.... (9 Replies)
Discussion started by: biglemon
9 Replies

3. Shell Programming and Scripting

Numbering

I'm trying to do a script that will look for a log file if it is already there change the name to another name. I.E if log.0 is there rename to log.1 rename log.1 to log.2 rename log.2 to log.3 and so on. Only thing is I got no idea where or what is the best command to use for this? ... (3 Replies)
Discussion started by: merlin
3 Replies

4. Programming

Reading special characters while converting sequential file to line sequential

We have to convert a sequential file to a 80 char line sequential file (HP UX platform).The sequential file contains special characters. which after conversion of the file to line sequential are getting coverted into "new line" or "tab" and file is getting distorted. Is there any way to read these... (2 Replies)
Discussion started by: Rajeshsu
2 Replies

5. UNIX for Advanced & Expert Users

numbering blanks

hello i'm trying to figure out how to number a blank line. For instance this : sed '/./=' file | sed '/./N; s/\n/ /' gives me 1 aaaa 2 bbbbbb 4 cccccc 5 ffkkkfff 6 ffsdfdfs I would like something like this: 1 aaaaa 2 3 bbbbbb 4 5 cccccc And so... (6 Replies)
Discussion started by: wisher115
6 Replies

6. Shell Programming and Scripting

help with numbering a file

Hi, All I need to do is number a file. The file looks like this > JJJJJJJJJJJJJJJJJJJJJ > JKJKJKKKKKKJJJ > MMMMYKKKJKKK what I want to do is number it so that theres a numerical value beside the >. >1 JJJJJJJJJJJJJJJJJJJJJ >2 JKJKJKKKKKKJJJ (2 Replies)
Discussion started by: kylle345
2 Replies

7. Shell Programming and Scripting

sequential to line sequential

Hi I have a file sequential way i.e. written in contineous mode and the Record Seperator is AM from which the record is seperated .Now to process I have to make line sequential,and more over record length is not same it varies as per the input address, AM1234563 John Murray 24 Old streeet old... (5 Replies)
Discussion started by: vakharia Mahesh
5 Replies

8. Programming

Tool to simulate non-sequential disk I/O (simulate db file sequential read) in C POSIX

Writing a Tool to simulate non-sequential disk I/O (simulate db file sequential read) in C POSIX I have over the years come across the same issue a couple of times, and it normally is that the read speed on SAN is absolutely atrocious when doing non-sequential I/O to the disks. Problem being of... (7 Replies)
Discussion started by: vrghost
7 Replies

9. Shell Programming and Scripting

Incremental numbering?

Would it be possible for a script to duplicate a file and incrementally number it? File in: XXX_007_0580_xxxx_v0016.aep File out: XXX_007_0580_xxxx_v0017.aep If someone knows of a way I'd love to see it. Thanks! (7 Replies)
Discussion started by: scribling
7 Replies

10. Shell Programming and Scripting

awk use sequential line numbering in output

The awk below produces an output with the original header and only the matching lines (which is good), but the output where the original line numbering in the match found on is used. I can not figure out how to sequentially number the output instead of using the original. I did try to add... (2 Replies)
Discussion started by: cmccabe
2 Replies
nl(1)							      General Commands Manual							     nl(1)

NAME
nl - line numbering filter SYNOPSIS
type] type] type] start#] incr] sep] width] format] num] delim] [file] DESCRIPTION
reads lines from the named file or the standard input if no file is named and reproduces the lines on the standard output. Lines are num- bered on the left in accordance with the command options in effect. views the text it reads in terms of logical pages. Line numbering is reset at the start of each logical page. A logical page consists of a header, a body, and a footer section. Empty sections are valid. Different line numbering options are independently available for header, body, and footer (e.g., no numbering of header and footer lines while numbering blank lines only in the body). The start of logical page sections are signaled by input lines containing nothing but the following delimiter character(s): | Line contents | Start of --------------+---------- ::: | header :: | body : | footer Unless told otherwise, assumes the text being read is in a single logical page body. Command options can appear in any order and can be intermingled with an optional file name. Only one file can be named. recognizes the following options: Specifies which logical page body lines are to be numbered. Recognized types and their meanings are: number all lines; number lines with printable text only; no line numbering; number only lines that contain the regular expression specified in string. Basic Regular Expression syntax is supported (see regexp(5)). The default type for logical page body is (text lines numbered). Same as except for header. Default type for logical page header is (no lines numbered). Same as except for footer. Default for logical page footer is (no lines numbered). Do not restart numbering at logical page delimiters. start# is the initial value used to number logical page lines. Default is incr is the increment value used to number logical page lines. Default is sep is the character or characters used in separating the line number and the corresponding text line. Default sep is a tab. width is the number of character columns to be used for the line number. Default width is format is the line numbering format. Recognized values are: left justified, leading zeroes suppressed; right justified, leading zeroes suppressed; right justified, leading zeroes kept. Default format is (right justified). num is the number of consecutive blank lines to be treated and numbered as a single line. For example, results in every third adjacent blank line being numbered if the appropriate and/or option is set. Default is The delimiter characters specifying the start of a logical page section can be changed from the default characters to two user-specified characters. If only one character is entered, the second character remains the default character No space should appear between the and the delimiter characters, how- ever, this restriction is not there for (see standards(5)) compliant To define a backslash as the delimiter, use two backslashes. EXTERNAL INFLUENCES
For information about the UNIX Standard environment, see standards(5). Environment Variables determines the collating sequence used in evaluating regular expressions. determines the characters matched by character class expressions in regular expressions. If or is not specified in the environment or is set to the empty string, the value of is used as a default for each unspecified or empty variable. If is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of If any internationalization variable contains an invalid setting, behaves as if all internationalization variables are set to "C". See environ(5). International Code Set Support Single-byte character code sets are supported. EXAMPLES
Number starting at line number 10, using an increment of ten. The logical page delimiters are and SEE ALSO
pr(1), environ(5), lang(5), regexp(5), standards(5). STANDARDS CONFORMANCE
nl(1)
All times are GMT -4. The time now is 07:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy