selective positions from a datafile


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting selective positions from a datafile
# 1  
Old 09-18-2006
Java selective positions from a datafile - Any Help pls !!!

Hi dear friends,

Im writing a shell script which has to select the strings based on the position.
but the problem is there is no field seperator.
Normally a datafile contains 2000 records (lines) and each line is of size 500 charecters.
I want to select the fields from all the lines which matches the charecter positions.

ex: from position(011:025) position(061:095) position(201:250) position(311:318) position(411:425) position(471:500).

any idea will be much appreciated.

Thanks in advance.
Ganapati

Last edited by ganapati; 09-18-2006 at 08:27 AM..
# 2  
Old 09-18-2006
Yes its possible to do but it would be better if you could post some sample input data and output you require.
# 3  
Old 09-18-2006
use simple cut command
Code:
cut -c1-4,6-8 filename

it will print field 1 to 4 and 6to 8 from file.
# 4  
Old 09-18-2006
aah I see. I thought OP was meant to select data based on characters from each line, without knowing the columns or having a field separator, therefor I asked for the sample input, it proved to be very dumb though Smilie
# 5  
Old 09-18-2006
Java

Smilie Thanks Dhruva and shereenmotor,

Sample datafile is:
ANP200606299e903984cls8898989ewe89CK20080820..................,

Required file would be based on charecter position as mentioned earlier.
Other than this charecter position there is no other logic applicable.

Many Thanks and Regards,
Ganapati
# 6  
Old 09-18-2006
You can decompoose the input file in records with the fold program.
The following command create split your file in fixed length (500) lines :
Code:
fold -w 500 filename

You can pipe the result of the command to another command for field extracting :
Code:
fold -w 500 filename | \
cut -c 11-25,61-95,201-250,311-318,411-425,471-500

There is no separator betwen the extracted fields.
If you want someone, ';' for example, you can do :
Code:
fold -w 500 filename | \
awk -v OFS=';' '
   { print substr($0,  11, 15),
           substr($0,  61, 35),
           substr($0, 201, 50),
           substr($0, 311,  8),
           substr($0, 411, 15),
           substr($0, 471, 30) } '

For a space separator, remove the -v OFS= option.

Another way to split the input file is to use the dd program :
Code:
dd obs=500 cbs=500 conv=unblock if=filename 2>/dev/null


Jean-Pierre.
# 7  
Old 09-19-2006
Could any one explain me the code to do the above task?

dd obs=500 cbs=500 conv=unblock if=filename 2>/dev/null

I dont know anything about dd obs. !!!!!

Thanks in advance
Ganapati
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read in numbers from a datafile

Hi, I want to be able to read numbers from many files which have the same general form as follows: C3H8 4.032258004031807E-002 Phi = 1.000000E+00 Tau = 5.749E+00 sL0 = 3.805542E+01 dL0 = 1.514926E-02 Tb = 2.328291E+03 Tu = 3.450E+02 Alpha = ... (3 Replies)
Discussion started by: lost.identity
3 Replies

2. Shell Programming and Scripting

Validating a datafile with the datatypes

I have two input files 1)datafile 2)metadata file. I have a metadata file like: field1datatypeformat1number2string3dateyy-mm-dd I have a data file like: 1234abc12-8-16 xyz234512-9-163456acd14-08-12 In the first row there is no correction as everything is inline with the metadata.... (3 Replies)
Discussion started by: bikky6
3 Replies

3. Shell Programming and Scripting

sorting the datafile in an order given in second datafile

Hi, I have two files: first input file is having 7-8 columns, and second data file is like I want to arrange my datafile1 in the order given in second data file, by comparing the seconddatafile with the second column of first file and print the entire line....also if any... (2 Replies)
Discussion started by: CAch
2 Replies

4. Shell Programming and Scripting

awk script replace positions if certain positions equal prescribed value

I am attempting to replace positions 44-46 with YYY if positions 48-50 = XXX. awk -F "" '{if (substr($0,48,3)=="XXX") $44="YYY"}1' OFS="" $filename > $tempfile But this is not working, 44-46 is still spaces in my tempfile instead of YYY. Any suggestions would be greatly appreciated. (9 Replies)
Discussion started by: halplessProblem
9 Replies

5. UNIX for Advanced & Expert Users

How do we know which processis creating a datafile

Hi, Is there any way we can find out which process is creating a partucular datafile.I know the user and group but i am just curios to know is there any way to find the process. Thanks (7 Replies)
Discussion started by: ukatru
7 Replies

6. Shell Programming and Scripting

Combine a datafile with Master datafile, emergent!

Hi guys, my supervisor has asked me to solve the problem in 7 days, I've taken 3 days to think about it but couldn't figure out any idea. Please give me some thoughts with the following problem, I have index.database that has only index date: 1994 1995 1996 1997 1998 1999 I have... (6 Replies)
Discussion started by: onthetopo
6 Replies

7. UNIX for Dummies Questions & Answers

Append filename to datafile

I am working on an shell script which checks for all the file starting with abc*.* and if file found then the filelines need to append the file name in begining can some one help with the filename appending... for i in `ls $filename*.csv` do echo $i --- NEED to append file name befor... (3 Replies)
Discussion started by: Satyagiri
3 Replies

8. Solaris

oracle datafile *dbf

Hi ,,,, I have move an oracle db from old server to a new server ( solaris 5.9 is the operating system ) my problem is that to new server the datafile ( *.dbf ) are in a different path ..... example old : /export/home/data/blobs ........... new /oracle/data/blobs....... how i can... (3 Replies)
Discussion started by: tt155
3 Replies

9. Shell Programming and Scripting

replace one section in a datafile

Hi: First, this is not a homework problem. I just need enough of a hint to get this going... My datafile (dataf.in) is made up of 10 sections. Each section begins with & and with && So it looks like this:------------------------------------- &section1 ...etc... && &section2 ...etc...... (4 Replies)
Discussion started by: Paprika
4 Replies
Login or Register to Ask a Question