fileutils - for working with files

  • line
    • line - print given line
  • rn
    • rn - rename files
  • gr
    • gr - grep files in current directory recursively
  • replace
    • replace - replace exact or regex patterns in files

9Feb20131kBline.0.1.tar.bz2
8Feb20133kBgr.0.4.tar.bz2
16Apr20114kBgr.0.3.arch.tar.bz2
7Apr20113kBgr.0.3.tar.bz2
5Apr20114kBgr.0.2.arch.tar.bz2
8Mar20112kBgr.0.2.tar.bz2
8Aug20081kBreplace.0.3.tar.bz2
7Aug20088kBrn.0.2.tar.bz2
5Aug20089kBrn.0.2.arch.tar.bz2
16Feb20061kBgr.0.1.tar.bz2
7Dec20051kBreplace.0.2.tar.bz2
14May20027kBrn.0.1.tar.bz2
30Dec19981kBreplace.0.1.tar.bz2

line: line -h

Name

line - print given line

Usage

line [OPTIONS] [FILE] LINENUMBER

Description

It prints line specified by LINENUMBER from given FILE. If environment variable LINEFILE is specified, the FILE can be omitted from command line and the LINEFILE will be used instead. To specify LINEFILE use:

export LINEFILE=filename.txt

Options

-h
This help.
-4
Print 4 lines prior and after requested line line. Accepted are -0 to -9 switches. Default is 3 lines.

Environment

$LINEFILE The default file.

Version

line.0.1 © R.Jaksa 2013, GPLv3


rn: rn -hh

Name

rn - rename files

Usage

rn [-h] [-r] [-q] [-i] [-im] [-v[012]] INFILES OUTFILES

rq [-h] [-r] [-q] [-i] [-im] [-v[012]] INFILES OUTFILES

Description

The rn renames INFILES files into OUTFILES files. The idea is that rn *.jpg img-*.jpg should prefix all the jpeg files with the img- prefix. However, due to shell expansion of the *, we must wrap the arguments into apostrophes: rn '*.jpg' 'img-*.jpg'.

The rq command is equal to rn -q and provides all the analysis of filenames without any actual rename (the query mode). Rq options are handled the same way, as the rn will handle them.

Rn usage is based on wildcards in INFILES and OUTFILES arguments. First wildcard from INFILES is mapped into first wildcard in OUTFILES and so on. Semantics of input and output wildcards is slightly different and is engineered specificaly for the rn.

Options

-h
This help.
-r
Operate on files and directories recursively.
-q
Query mode, useful to test what the rn will do. With the -q option, rn will not rename any file. It will print analysis of filenames and the list of files which have to be renamed. Other options are fully respected in query mode too.
-i
Interactive mode. Ask prior every rename operation.
-im
Interactive mode. Ask once before the rename of all files.
-v
Verbose mode (also -v1).
-v0
Quiet mode, without any messages.
-v2
All mesages from verbose and also from query mode.

Infiles

*
Any string.
?
Any character.
#
Any number.
##
Any 2-character number.
#4
Any 4-character number (the same like ####).
#[2]
The number 2 in any form (eg: 2 02 0002).
##[3,12,2,1]
Numbers 03,12,02,01.
#[3-5]
Any number from interval <3,5>.
#[2-50:2]
Any even number from interval <2,50>.

Outfiles

*
Matches variable substring from input. Variable substring is the substring defined by the wildcard in INFILES.
??
The same like * (or ? or ???).
$3
Exactly the 3rd substring from input. Works for variable and for fixed substrings too.
.$
Suffix of input (for 023.jpg it is .jpg).
^
Directory part of path in recursive mode (eg: /usr/).
#
Numerical argument. If it corresponds to INFILES numerical argument, then the number from input filename is copied into output filename. If not, numbering starts with 1 and is incremented by 1 for every other file.
#[-]
Numbering in descending order. Either finished with 1, or starting with highest number among input numbers.
#4
Numbers with the length of 4 (eg: 0001 0002 0003 ...).
###
The same like #3.
#[8-12]
Numbers 8,9,10,11,12.
#[11-9]
Numbers 11,10,9.
#[8,6,9]
Numbers 8,6,9.
#[8-12:2]
Every second number (8,10,12).
#[8-10:/2]
Increment every second number (8,8,10,10).
#[8,6,9:/2]
Numbers 8,8,6,6,9,9.
###[8]
Number 008.
#[8-h]
The h is the highest number among inputs.
#[l-13]
The l is the lowest number among inputs.

Examples

rn -r '*.jpg' '###.$'
Rename all jpegs into 011.jpg form.
rn -r '*.jpg' '^###.$'
Like previous, but leave files in subdirs.
rn 'summer-*.*' '*.*'
Remove summer- prefixes from filenames.

Install

  1. Correct the #!/bin/perl path in the 1st line of rn file to point to your perl binary.
  2. Copy the rn file into some your .../bin directory.
  3. Make symbolic link rq pointing to the rn file (ln -s rn rq).

Version

rn.0.2 © R.Jaksa 2002, GPLv3


gr: gr -h

Name

gr - grep files in current directory recursively

Usage

gr [OPTIONS] PATTERN [FILEPATTERN...]

Description

Recursively grep files in current directory for given PATTERN. If FILEPATTERN is specified, grep only matching files. Specifying of multiple filepatterns is possible. The gr is a perl script wrapper for the system grep command. The search is divided into batches of 100 files.

Options

-h
This help.
-d
Debug.
-f
FILEPATTERN Specify FILEPATTERN explicitly.
-NUM
Where NUM is any number. Print surronding NUM lines.
-nm
The nm processing of ELF files.

Files

.gr
Per directory setup file.

The .gr recognizes only the exclude keyword for excluding specified files from search. Following example will exclude a.out and all object files from the search.

exclude: *.o a.out

Examples

gr #include
Will grep all the files in current directory (recursively) for "#include".
gr '#include "plugin.h"' '*.cpp'
Will grep only the files *.cpp. (recursively in current directory). The grep pattern is whole #include "plugin.h". Apostrophes to enclose arguments are necessary, because the spaces, because quotes, and because the character '*' in '*.cpp', this way we do avoid their expansion by shell.

Version

gr.0.4 © R.Jaksa 2006,2013 GPLv3


replace: replace -hh

Name

replace - replace exact or regex patterns in files

Usage

replace [-exact|-regex] PATTERN REPLACEMENT FILES

Description

Default is exact patterns behaviour. Exact patterns are processed line by line, while regex patterns are matched on the file as whole.

Variables $1,$2,$3 are supported in the regex mode.

Options

-exact
Exact pattern format.
-regex
Regex pattern format.

Install

  1. Correct the #!/bin/perl path in the 1st line of replace file to point to your perl binary.
  2. Copy the replace file into some your .../bin directory.

Version

replace.0.3 © R.Jaksa 2008, GPLv3



9.2.2013