12-04-2007
Well, I appreciate the urge to "just do it" in ksh - so here goes:
Input:
Quote:
$ cat in.txt
mgr1.dbf
tool.dbf
usR.dbf
wow19.dbf
wow2wow.dbf
char14between13.dbf
11num@ber12.dbf
Script:
Quote:
#!/usr/bin/ksh
infile=in.txt
cat $infile | while read fname ; do
newname=$(echo "${fname}" |tr "[A-Z]" "[a-z]" |tr "[a-z]#_@-" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" |tr -s "x")
num=$(echo $newname |cut -d"." -f1|awk -F"x" '{print $NF}')
if [ -z "${num}" ] ; then
num=1
newnum=$((num+1))
final=$(echo $fname|sed -e "s/\./$newnum\./g")
else
newnum=$((num+1))
final=$(echo $fname|sed -e "s/$num\./$newnum\./g")
fi
echo "$fname -> $final"
done
Result:
Quote:
$ inc.sh
mgr1.dbf -> mgr2.dbf
tool.dbf -> tool2.dbf
usR.dbf -> usR2.dbf
wow19.dbf -> wow20.dbf
wow2wow.dbf -> wow2wow2.dbf
char14between13.dbf -> char14between14.dbf
11num@ber12.dbf ->
11num@ber13.dbf
Obviously this is quite brittle but for the kind of input provided, this should do.
Note: done using default ksh on SunOS db012a 5.8 Generic_117350-35 sun4us sparc FJSV,GPUZC-M
HTH
10 More Discussions You Might Find Interesting
1. UNIX for Advanced & Expert Users
hi all...
i have a big problem, and i hope someone can help me...
i have a flat file, and its columns are separated by comma (CSV), something like this:
78 , 204R180 , 90/100 , 200001 , 12 ,200002 ,13 .....
78 , 204R180 , 90/100 , 200001 , 29 ,200002 ,30 .....
78 , 204R180 , 90/100 ,... (0 Replies)
Discussion started by: DebianJ
0 Replies
2. HP-UX
Hi, I'm using HPUX 11.11 on Vizualize B180L
our productive machines have 64 bit kernel
# file vmunix
vmunix: ELF-64 executable object file - PA-RISC 2.0 (LP64)
I got one test system, which should have the same HW (i was told it is the same HW)
hpuxtest:/stand-->file... (3 Replies)
Discussion started by: funksen
3 Replies
3. Shell Programming and Scripting
Hi I have a file in the following format
I have to convert this into four files , in the format as below.
Data under Process SFA SUccess Section gets into file Named SFA_SUCCESS inthe following format
ctr1,120
ctr2,1785
Data under Process SFA FAil gets into file Named SFA_Fail inthe... (2 Replies)
Discussion started by: sapics
2 Replies
4. Shell Programming and Scripting
hi all,
i have a big problem and i don't know what to do. This is the thing: i have a flat file with 26 fields, which are separated by ';'
by example, i have this:
Peter;Smith;2005;200508; .........
if the lengths of the fields are:
field 1: Alphanumeric - field 2: Alphanumeric - field... (4 Replies)
Discussion started by: DebianJ
4 Replies
5. Shell Programming and Scripting
Hi All,
I have a file like
john::208:johnson
john::208:mery
john::208:test
admin:*:1:johnson
admin:*:1:test
and wanna convert this as
john::208:johnson,mery,test
admin:*:1:johnson,test
please help me to create a script for this
thanks in advance
John (4 Replies)
Discussion started by: johnsonpk
4 Replies
6. Shell Programming and Scripting
In order to perform some arithmetical operations on 64 bit double I need to transform of the binary representation of a 64 bit double to a 64
bit integer do the operations and then transform back to 64 bit double.
I understand bash and bc doesn't allow to do that. I think my only tool left is... (2 Replies)
Discussion started by: Zephyr
2 Replies
7. Shell Programming and Scripting
Hello!
I have a textfile that look like this:
"83d1:46:2b";"20091008190000";"Rögle BK - Skellefteå";"Swedish"
"d4c:46:21";"20091008190000";"Södertälje - Brynäs";"Swedish"
"d4b:46:2";"20091008190000";"HV 71 - Färjestad";"Swedish"
"838:46:b";"20091010160000";"Skellefteå - HV 71";"Swedish"... (2 Replies)
Discussion started by: condmaster
2 Replies
8. Shell Programming and Scripting
Hi
I have a file with this inside:
How can I change it to:
thanks a lot
regards
Israel. (3 Replies)
Discussion started by: iga3725
3 Replies
9. Shell Programming and Scripting
Hi,
How can I change following file name in a bash script?
From file names: myfile-module-1.0-3.0.el6.x86_64.package
To file names: myfile-module1_0-1.0-3.0.el6.x86_64.package
^ ^ ^ ^ ^ ^ ^ ^
Basically, the digit 1.0 is a version number, the digit 3.0 is... (11 Replies)
Discussion started by: hce
11 Replies
10. Shell Programming and Scripting
gpio_rw = gpiochip162
audio_aplay = HDMI_0
audio_aplay = HDMI_1
audio_aplay = HDMI_2
graphic_xrandr_show = USB1
graphic_xrandr_show = USB2
graphic_xrandr_show = USB3
graphic_change_resolution = eDP1
gpio_rw = "gpiochip162"
audio_aplay = "HDMI_0 HDMI_1 HDMI_2"
graphic_xrandr_show =... (3 Replies)
Discussion started by: yanglei_fage
3 Replies
LEARN ABOUT DEBIAN
grass-dbf
grass-dbf(1grass) Grass User's Manual grass-dbf(1grass)
NAME
grass-dbf - DBF driver
DBF driver DBF driver in GRASS
Defining the DBF driver
The DBF driver is the default driver, in theory no user interaction is required. However, if the settings should be set back from a differ-
ent to the DBF driver, the following step is required:
# keep single quotes:
db.connect driver=dbf database='$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/'
db.connect -p
The dbf/ subdirectory in the mapset must exist or must be created by the user.
Creating a DBF table
Usually DBF tables are created by GRASS when generating a vector map with attributes (and using DBF as default attribute driver).
If a DBF table has to be created manually, db.execute can be used or a spreadsheet application. Also db.copy is sometimes useful as well as
db.in.ogr to import external tables.
Supported SQL commands by DBF driver
ALTER TABLE table ADD [COLUMN] columndef
ALTER TABLE table DROP COLUMN colname
CREATE TABLE table ( columndefs )
DROP TABLE table
SELECT columns FROM table
SELECT columns FROM table WHERE condition
SELECT columns FROM table ORDER BY column
DELETE FROM table
DELETE FROM table WHERE condition
INSERT INTO table VALUES (value1[,value2,...])
INSERT INTO table ( column1[,column2,...] ) VALUES (value1[,value2,...])
UPDATE table SET assignment1[,assignment2,...]
UPDATE table SET assignment1[,assignment2,...] WHERE condition
Operators available in conditions
"=" : equal
"<" : smaller than
"<=" : smaller/equal than
">" : larger than
">=" : larger/equal than
"<>" : not equal
"~" : Substring matching (non-standard SQL)
"%" : Substring matching (limited functionality)
Arithmetic expressions using constants and field values are allowed in condition clauses and in the RHS of assignments.
Usual precedence rules and bracketing (using '(' and ')') are supported.
Type conversion is performed if necessary (experimental).
Conditions allow boolean expressions using the AND, OR and NOT operators, with the usual precedence rules.
NULLs can be tested by 'colname IS NULL' in conditions. The negation is 'colname NOT NULL'.
Sorting: Empty fields in a character column are sorted to the end.
LIMITATIONS OF THE DBF DRIVER
The DBF driver supports only a few SQL statements since the DBF tables are intended for simple table storage. DBF column names are limited
to 10 characters (as defined in the DBF specifications). For example,
aggregate functions (sum, count, min, max,...) are not supported in SELECT clauses;
mathematic functions (sin, cos, exp, log,...) are not supported in expressions;
SQL query with IN are not supported.
ERROR MESSAGES
An error message such as:
DBMI-DBF driver error:
SQL parser error: syntax error, unexpected NAME processing 'IN'..
indicates that an unsupported SQL statement (here, 'IN') was used. The only solution is to switch the DBMI backend to a real SQL engine
(SQLite, PostgreSQL, MySQL etc.). See SQL support in GRASS GIS.
An error message such as:
DBMI-DBF driver error:
SQL parser error: syntax error, unexpected DESC, expecting NAME processing 'DESC'
indicates that a column name corresponds to a reserved SQL word (here: 'DESC'). A different column name should be used. If this happens
during import with v.in.ogr, the cnames parameter can be used to assign different column names on the fly.
SEE ALSO
db.connect, SQL support in GRASS GIS
DBF Specifications (Shapelib)
Last changed: $Date: 2011-02-07 18:59:50 +0100 (Mon, 07 Feb 2011) $
Help Index
GRASS 6.4.2 grass-dbf(1grass)