LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 03-02-2012, 06:17 PM   #1
CLD422
LQ Newbie
 
Registered: Mar 2012
Posts: 2

Rep: Reputation: Disabled
Split large .lvm file when column number changes


I have several large .lvm files which contain 2 to 5 columns. The problem is that they can start with 4 columns and midway through become 2 columns. Then back to 4. I need to split these files at each point where the column number changes. The two files I am working with currently contain ~99,900,00 lines each. Below is an exmple of what the data looks like when it switches. Any help would be much appreciated.

--I have tried 'split' and looked at 'csplit' - it looks like 'awk' may have the ability to do this, but I don't have enough linux know-how.

0.761719 0.000000
0.750000 0.000000
0.754395 0.000000
0.748535 0.000000
0.751465 0.000000
0.747070 0.000000
0.745605 0.000000
0.747070 0.000000
0.742676 0.000000
0.741211 0.000000
0.752930 0.000000
0.748535 0.000000
0.747070 0.000000
0.747070 0.000000
0.748535 0.000000
0.752930 0.000000
0.763184 0.000000
0.763184 0.000000
0.757324 0.000000
0.754395 0.000000
0.757324 0.000000
0.754395 0.000000
0.755859 0.000000
0.760254 0.000000
0.750000 0.000000
0.751465 0.000000
0.751465 0.000000
0.755859 0.000000
0.747070 0.000000
0.750000 0.000000
0.000000 0.000000 0.000000 0.741211
0.000000 0.000000 0.000000 0.750000
0.000000 0.000000 0.000000 0.741211
0.000000 0.000000 0.000000 0.745605
0.000000 0.000000 0.000000 0.736816
0.000000 0.000000 0.000000 0.747070
0.000000 0.000000 0.000000 0.747070
0.000000 0.000000 0.000000 0.751465
0.000000 0.000000 0.000000 0.751465
0.000000 0.000000 0.000000 0.748535
0.000000 0.000000 0.000000 0.744141
0.000000 0.000000 0.000000 0.745605
0.000000 0.000000 0.000000 0.741211
0.000000 0.000000 0.000000 0.748535
0.000000 0.000000 0.000000 0.752930
0.000000 0.000000 0.000000 0.764648
0.000000 0.000000 0.000000 0.761719
 
Old 03-02-2012, 11:00 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Maybe something like:
Code:
awk 'x != NF{x = NF}{print > "file"x}' file
This will place all similar numbered columns into files based on number of columns.
 
1 members found this post helpful.
Old 03-03-2012, 09:15 AM   #3
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
[untested]
Code:
cat file.txt | while read line
do
 if [`echo $line | wc -w` -eq 2 ]
 then
  echo $line >> file.2-columns
 fi
 if [`echo $line | wc -w` -eq 4 ]
 then
  echo $line >> file.4-columns
 fi
done
 
Old 03-05-2012, 04:51 PM   #4
CLD422
LQ Newbie
 
Registered: Mar 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks!!

grail, Thank you very much! That is exactly what I needed.
 
  


Reply



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
[quick] trying to split a large file but linux says it's to large steve51184 Linux - General 16 05-06-2008 07:40 AM
how do I split large file by string? khairil Programming 5 04-28-2008 10:37 PM
Split large file into multiples jdozarchuk Linux - Newbie 1 11-04-2004 09:42 AM
split a large mpeg file into two zstingx Linux - General 3 11-06-2003 06:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:49 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration