Sponsored Content
Top Forums Shell Programming and Scripting Get 4 character each from 2 different fields concatenate and add as a new field Post 302342021 by kshji on Friday 7th of August 2009 08:04:46 AM
Old 08-07-2009
Code:
#!/bin/ksh
# or bash
# script
while read f1 f2 f3 f4 f5 fx
do
         fnew="${f1:0:3}${f2:0:3}"
         echo "$f1 $f2 $fnew $f3 $f4 $f5"
done

Code:
chmod a+rx script
./script < infile > outfile



---------- Post updated at 03:04 PM ---------- Previous update was at 03:02 PM ----------

Awk is faster.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sorting on two fields time field and number field

Hi, I have a file that has data in it that says 00:01:48.233 1212 00:01:56.233 345 00:09:01.221 5678 00:12:23.321 93444 The file has more line than this but i just wanted to put in a snippet to ask how I would get the highest number with time stamp into another file. So from the above... (2 Replies)
Discussion started by: pat4519
2 Replies

2. Shell Programming and Scripting

awk script to (un)/concatenate fields in file

Hi everyone, I'm trying to use the "join" function for more than 1 field. Since it's not possible as it is, I want to take my input files and concatenate the joining fields as 1 field (separated by "|"). I wrote 2 awk script to do and undo it (see below). However I'm new to awk and I'm certain I... (5 Replies)
Discussion started by: anthony.cros
5 Replies

3. Shell Programming and Scripting

Count number of occurences of a character in a field defined by the character in another field

Hello, I have a text file with n lines in the following format (9 column fields): Example: contig00012 149606 G C 49 68 60 18 c$cccccacccccccccc^c I need to count the number of lower-case and upper-case occurences in column 9, respectively, of the... (3 Replies)
Discussion started by: s052866
3 Replies

4. Shell Programming and Scripting

AWK : Add Fields of lines with matching field

Dear All, I would like to add values of a field, if the lines match in a certain field. Then I would like to divide the sum though the number of lines that have a matched field. This is the Input: Input: Test1 5 Test1 10 Test2 2 Test2 5 Test2 13 Test3 4 Output: Test1 7.5 Test1 7.5... (6 Replies)
Discussion started by: DerSeb
6 Replies

5. Shell Programming and Scripting

Concatenate last field values for all occurences

Hello all, Maybe you can help me with an awk script to get what I need. I have the input file with format below: REQUEST|79023787741690|738227864597|985 REQUEST|79024002151717|738229423534|985 REQUEST|79024002151717|738229423534|*985 NDS-REQUEST|79024002151717|738229423534 ... (4 Replies)
Discussion started by: Ophiuchus
4 Replies

6. Shell Programming and Scripting

How to print 1st field and last 2 fields together and the rest of the fields after it using awk?

Hi experts, I need to print the first field first then last two fields should come next and then i need to print rest of the fields. Input : a1,abc,jsd,fhf,fkk,b1,b2 a2,acb,dfg,ghj,b3,c4 a3,djf,wdjg,fkg,dff,ggk,d4,d5 Expected output: a1,b1,b2,abc,jsd,fhf,fkk... (6 Replies)
Discussion started by: 100bees
6 Replies

7. Shell Programming and Scripting

Display combination of 4 field uniqe record and along with concatenate 5th and 6th field.

Table ACN|NAME|CITY|CTY|NO1|NO2 115|AKKK|ASH|IND|10|15 115|AKKK|ASH|IND|20|20 115|AKKK|ASH|IND|30|35 115|AKKK|ASH|IND|30|35 112|ABC|FL|USA|15|15 112|ABC|FL|USA|25|20 112|ABC|FL|USA|25|45 i have written shell script using cut command and awk programming getting error correct it and add... (5 Replies)
Discussion started by: udhal
5 Replies

8. Shell Programming and Scripting

Inserting a field without disturbing field separator on other fields

Hi All, I have the input as below: cat input 032016002 2.891 97.109 16.605 27.172 24.017 32.207 0.233 0.021 39.810 0.077 0.026 19.644 13.882 0.131 11.646 0.102 11.449 76.265 23.735 16.991 83.009 8.840 91.160 0.020 99.980 52.102 47.898 44.004 55.996 39.963 18.625 0.121 1.126 40.189... (15 Replies)
Discussion started by: am24
15 Replies

9. Shell Programming and Scripting

sed to add field heards to specific fields

I have tab delimited input that prints out in the format below: I am trying to add field headers to $5 and $6. Not sure if sed is the best tool but my attempt is below. Thank you :). $5 = REF $6 = ALT file ID CHR START STOP 123 1 100 200 A ... (6 Replies)
Discussion started by: cmccabe
6 Replies

10. Shell Programming and Scripting

awk to add plus or minus to fields and split another field

In the tab-delimited input below I am trying to use awk to -10 from $2 and +10 to $3. Something like awk -F'\t' -v OFS='\t' -v s=10 '{split($4,a,":"); print $1,$2-s,$3+s,a,$5,$6} | awk {split(a,b,"-"); print $1,$2-s,$3+s,b-s,b+s,$5,$6}' input should do that. I also need to -10 from $4... (2 Replies)
Discussion started by: cmccabe
2 Replies
DBF2MYSQL(1)						      General Commands Manual						      DBF2MYSQL(1)

NAME
dbf2mysql, mysql2dbf - convert between xBase and MySQL databases SYNOPSIS
dbf2mysql [-v[v]] [-f] [-u|-l] [-n] [-o field[,field]] [-e conversion-file] [-s old-name=new-name[,old-name=new-name]] [-i field[,field]] [-d database] [-t table] [-c[c]] [-p primary] [-h host] [-F] [-q] [-r] [-x] [-P password] [-U user] dbf-file mysql2dbf [-v[v]] [-u|-l] -d database -t table [-h host] [-q query] [-P password] [-U user] dbf-file DESCRIPTION
dbf2mysql takes an xBase file and sends queries to an MySQL server to insert it into an MySQL table. mysql2dbf dumps a MySQL table to a dbf file. OPTIONS
-v Produce some status output. -vv More verbose. -vvv Even more verbose: produce a progress report. -f Translate all field names in the xBase file to lowercase. -u Translate all text in the xBase file to uppercase. -l Translate all text in the xBase file to lowercase. -n Allow NULL fields: 'NOT NULL' will be not added in table creation statement. -o field[,field[,...]] List fields to insert into MySQL database. Primary use is to ease import of complex dbf files where we want only few fields. NOTE: -o is processed before substitution (-s), so you have to use dbf field names here. -e conversion-file Specify file for CHAR fields conversion. File format is: 1st line: number of characters to convert (number of lines). Further lines: <char_to_convert> <char_after_conversion>. -s old-name=new-name[,old-name=new-name[,...]] Takes a list of field name/new field name pairs. Primary use is to avoid conflicts between field names and MySQL reserved keywords. When the new field name is empty, the field is skipped in both the CREATE clause and the INSERT clauses, i.e. it will not be present in the MySQL table. For example: -s ORDER=HORDER,REMARKS=,STAT1=STATUS1 -i field[,field[,...]] List fields to be indexed. MySQL field names should be used here. -d database Select the database to insert into. Default is 'test'. -t table Select the table to insert into. Default is 'test'. -c[c] Create table if one doesn't exist already. If the table already exists, drop it and build a new one. The default is to insert all data into the named table. If -cc is specified, no records will be inserted. -p primary Select the primary key. You have to give the exact field name. -h host Select the host to insert into. Untested. -F Fixed length records. (By default CHAR is saved as VARCHAR.) -q dbf2mysql: "Quick" mode. Inserts data via temporary file using 'LOAD DATA INFILE' MySQL statement. This increased insertion speed on my PC 2-2.5 times. Also note that during whole 'LOAD DATA' affected table is locked. mysql2dbf: Specify custom query to use. -r Trim trailing and leading whitespace from CHAR type fields data. -x Start each table with _rec and _timestamp fields. -P password Specify password on the MySQL server. -U user Specify user on the MySQL server. BUGS
mysql2dbf can't write MEMO files at this time. Possibly incorrect field lengths for REAL numbers. AUTHORS
Originally written by Maarten Boekhold <boekhold@cindy.et.tudelft.nl>, Oct 1995. Patched for MySQL by Michael Widenius <monty@analytikerna.se>, 3 Nov 1996. Manual page written for Debian GNU/Linux from README by Heiko Schlittermann <heiko@lotte.sax.de>, Aug 1997; updated by Matej Vela <vela@debian.org>, Nov 2001. COPYRIGHT
Use this piece of software as you want, modify it to suit your needs, but please leave my name in place ok? :) DISCLAIMER
The authors do not accept any responsibility for possible damage you get as result of using this program. Debian Project 2001-11-18 DBF2MYSQL(1)
All times are GMT -4. The time now is 10:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy