Read a file and write to new file with some condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read a file and write to new file with some condition
# 1  
Old 12-08-2012
Read a file and write to new file with some condition

Hi....

I have a data file, which I want to split and write to new file...it looks like this...
Code:
Column1    column2    Column 3
1                 28.25          36.42  -----Read 
5                 28.26          36.42
10               28.23          36.43
15               28.22          36.43   --------- write to new file
5                 28.94          34.97   --------- Again read
10               28.95          34.98
15               28.96          34.99
20               28.95          34.99
25               28.96          34.99
30               28.96          34.99  ----------Write to another new file
2                 28.19          36.43  ---------Again read
3                 28.18          36.43
4                 28.18          36.43
5                 28.18          36.44
6                 28.19          36.45

------write to new file..

Depends on the change in value of 1st column, script has to write data to new file...

new file should contain data like this..
1st file

Code:
Column1    column2    Column 3
1                 28.25          36.42  
5                 28.26          36.42
10               28.23          36.43
15               28.22          36.43

2nd file
Code:
Column1    column2    Column 3
5                 28.94          34.97  
10               28.95          34.98
15               28.96          34.99
20               28.95          34.99
25               28.96          34.99
30               28.96          34.99


Here I have attached one sample data file please have look...
# 2  
Old 12-08-2012
You already had a similar thread here. Please continue in that thread..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl write and read on same file

Hi, I am trying to do a write operation followed by a read operation on the same file through Perl, expecting the output produced by read to contain the new lines added, as follows: #! /usr/bin/perl -w open FH, "+< testfile" or die "$@"; print FH "New content added\n"; while (my $line =... (1 Reply)
Discussion started by: royalibrahim
1 Replies

2. Shell Programming and Scripting

Read and write in the file

Hello Guys, How all are doing? I have an issue in Unix and want help from all of you I have a file in UNIX which it read by line by line , If at the end of line '0' is written the it should fetch that line into another file and change '0' to '1' and If at the end of line '1' is written then it... (10 Replies)
Discussion started by: adisky123
10 Replies

3. Shell Programming and Scripting

Read column from file and delete rows with some condition..

Hi.... I have a need of script to do delete row whenever condition is true.... 2.16 (3) 1 3 9999 0 (1) (0) 34.42 (4) 1 3 9999 37 (2) (3) 34.38 (4) 1 3 9999 64 (2) (3) 34.4 (4) 1 3 1 ... (13 Replies)
Discussion started by: nex_asp
13 Replies

4. Shell Programming and Scripting

File Read and Write

I have got a file in following format: AAAAAAA BBBBBBBB CCCCCCC DDDDDDD I am trying to read this file and out put it in following format: AAAAAAA,BBBBBBB,CCCCCCC,DDDDDD Preferred method is shell or Perl. Any help appreciated. (11 Replies)
Discussion started by: Araoki
11 Replies

5. Shell Programming and Scripting

how read specific line in a file and write it in a new text file?

I have list of files in a directory 'dir'. Each file is of type HTML. I need to read each file and get the string which starts with 'http' and write them in a new text file. How can i do this shell scripting? file1.html <head> <url>http://www.google.com</url> </head> file2.html <head>... (6 Replies)
Discussion started by: vel4ever
6 Replies

6. Shell Programming and Scripting

read and write to xml file

hi i am quite new to shell scripting and need help in reading and writing in xml file i have an xml file with format: <main> <store> <name>ABC</name> <flag>0</flag> <size>123<size> </store> <store> <name>DEF</name> ... (2 Replies)
Discussion started by: kichu
2 Replies

7. Shell Programming and Scripting

Read the apecific data from one file and write into another file

Hi, I would like to read the specific data from file and write the data in the new file. My data input is something like this.. <EXROP:R=TJ0311T; ROUTE DATA R ROUTE PARAMETERS TJ0311T DETY=UPDR TTRANS=1 FNC=3 MA=628160955000 R=TJ0311D ... (3 Replies)
Discussion started by: bha148
3 Replies

8. Shell Programming and Scripting

read and write from a file

I have tried to show the file name whose size is greater than 200 byte in current directory. Please help me. ls -l | tr -s " " " " | cut -f 5,9 -d " " >out.txt #set -a x `cat out.txt` i=0 `cat out.txt` | while do read x echo $x #re=200 j=0 if }" < "200" ] then echo $j j=`expr $j... (2 Replies)
Discussion started by: rinku
2 Replies

9. Shell Programming and Scripting

Read file based on condition

Hi Friends, Can any one help with this: I have a huge file with the format as A SAM 4637 B DEPT1 4758 MILAN A SMITH 46585 B DEPT2 5385 HARRYIS B SAMUL 63547 GEORGE B DANIEL 899 BOISE A FRES 736 74638 I have to read this file and write only the records that starts with "B" only ... (5 Replies)
Discussion started by: sbasetty
5 Replies

10. Shell Programming and Scripting

need to read a file and keep waiting till it satisfies some condition

In my script i am writing to a counter file the no of processes i had started, that is each time i start a process, i will increment the content of counter file and also when the process ends i will decrement the content of the file. after this i do some other activities, by now i want to... (1 Reply)
Discussion started by: senthilk615
1 Replies
Login or Register to Ask a Question