LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-17-2005, 05:08 PM   #1
eilison
LQ Newbie
 
Registered: May 2005
Location: CA
Posts: 2

Rep: Reputation: 0
locate and delete a line from a file


Hi, folks,

How to locate a special line in a file and move it to another file?

I got a fixed length file from mainframe. The file looks like this:

source.txt
-------------------
100 0.1111 0.1111
200 0.2222 0.2222
300 0.3333 0.3333
400 0.4444 0.4444
999 0.9999 0.9999


I wanna split the file into two files with script, the desired output files are supposed to be like:

output1.txt
-------------------
100 0.1111 0.1111
200 0.2222 0.2222
300 0.3333 0.3333
400 0.4444 0.4444


output2.txt
-------------------
999 0.9999 0.9999

We can tell the special line by the first column with a special number like 999. but I don't know how to locate the special line in script, copy it to anohter file before delete it from the source file.

I guess we can do it with sed, awk, etc. but it's been a long time since last time i used them.
Could you shed some light on it?
eilison
Thanks in advance!
 
Old 05-17-2005, 05:45 PM   #2
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 46
$ grep '^999' input > out2
$ sed -e '/^999/d' input > out1

hth. If not, rtm.

--Jonas
 
Old 05-17-2005, 06:05 PM   #3
eilison
LQ Newbie
 
Registered: May 2005
Location: CA
Posts: 2

Original Poster
Rep: Reputation: 0
Yes, it works!
Thanks, jonaskoelker!
 
Old 05-17-2005, 06:07 PM   #4
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 46
yw
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
unix shell script:How to delete the first line in a file?? rche3252 Programming 6 03-03-2010 07:32 AM
[SOLVED] delete the end of each line in a file with sed angel115 Linux - Newbie 3 11-16-2005 04:41 PM
How do I delete a line in a file with fstream (C++)? CrazyHoboMan Programming 3 08-18-2005 02:06 AM
Delete line from flat text file in C zaichik Programming 6 01-26-2005 06:16 PM
How to delete the first line of evrer .java file recursively ththomas Programming 2 03-08-2004 08:55 AM


All times are GMT -5. The time now is 05:38 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration