Results 1 to 5 of 5
Ok, another question, How do I break up a file in bash. I have an input file that has some stuff thats gonna be done to it. However, i need ...
- 04-22-2007 #1Just Joined!
- Join Date
- Sep 2005
- Posts
- 99
breaking up a file in bash
Ok, another question, How do I break up a file in bash. I have an input file that has some stuff thats gonna be done to it. However, i need to distiguish between the stuff above the blank line and below it. Here is the input file:
so basically, i need everything above the blank line to be in one file and everything below the blank line to be in another file. Both the stuff above and below can be of varied line numbers. I saw the split command, i don't think that will work, i need something that detects the new line and then takes everything after it and appends it to a file. So when the Zoom part starts. Those lines need to be taken out of that file and put in another file. Anyone know how to do this?y 10 x -11.2
x 7.65 Y 3.2
x 9.3 y 1.2
X -5.6 y 14.6
Y 4.6 x 2.7
Y 5.89 X 12.45
-1.2 -4.6
y -7.6 X 8.2
x y 2.3
Y x 4.5
Zoom 50%
Zoom 100
60%
- 04-22-2007 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
This:
echoes the lines before the first blank line andCode:sed '/^$/q'
echoes the lines after the first blank line.Code:sed '1,/^$/d'
Regards
- 04-22-2007 #3Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
The key is detecting an empty line.Code:while read var do TEST and write as appropriate done
case 1: pure bash
use loop structure above, TEST could include
a. old style form for zero-length string or equality to null string, [ ]
b. new style form for string comparison, [[ ]]
case 2: bash with other utilities
use loop structure above, TEST is more general using grep
case 3: sed
as Franklin52 noted
case 4: csplit
designed for this kind of situation
See man pages bash, sed, csplit for details. Post code when you have questions ...cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 04-22-2007 #4Just Joined!
- Join Date
- Sep 2005
- Posts
- 99
thanks for the replies. I have one more question about sed. I have to be able to detect and remove comments from a file. A comment starts with a /* and ends with a */ i need to detect those and any lines between those and delete them. Thanks.
- 04-23-2007 #5Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Have a read of this first:
http://tldp.org/LDP/abs/html/string-manipulation.html
Regards


Reply With Quote