How to split files using shell script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to split files using shell script?
# 1  
Old 08-10-2014
How to split files using shell script?

Code:
solid top
facet normal 0    1    0
outer loop
vertex 0    1    0
vertex 1    1    1
vertex 1    1     0
endloop
endfacet
facet normal 0    1    0
outer loop
vertex 0    1    0
vertex 0    1    1
vertex 1    1     1
endloop
endfacet
endsolid top
solid bottom
facet normal 0    -1    0
outer loop
vertex 0    0    1
vertex 0    0    0
vertex 1    0     0
endloop
endfacet
facet normal 0    -1    0
outer loop
vertex 0    0    1
vertex 1    0    0
vertex 1    0     1
endloop
endfacet
endsolid bottom

Hi All,

Hope everyone enjoying weekend. I need little help.
Above is the file format. I want to split it into two stl files namely top.stl bottom.stl. How can I do it?
Also, There is no limit for number of solid regions. shell script should work for any number of solids.

Regards,
linuxUser_
# 2  
Old 08-10-2014
Give us the expected output files
# 3  
Old 08-10-2014
Thanks for the reply Smilie. There are my expected files.
top.stl
Code:
solid top 
facet normal 0    1    0 
outer loop 
vertex 0    1    0 
vertex 1    1    1 
vertex 1    1     0 
endloop 
endfacet 
facet normal 0    1    0 
outer loop 
vertex 0    1    0 
vertex 0    1    1 
vertex 1    1     1 
endloop 
endfacet 
endsolid top

bottom.stl
Code:
solid bottom 
facet normal 0    -1    0 
outer loop 
vertex 0    0    1 
vertex 0    0    0 
vertex 1    0     0 
endloop 
endfacet 
facet normal 0    -1    0 
outer loop 
vertex 0    0    1 
vertex 1    0    0 
vertex 1    0     1 
endloop 
endfacet 
endsolid bottom

Regards,
linuxUser_

---------- Post updated at 11:29 AM ---------- Previous update was at 11:27 AM ----------

Oops no. Something went wrong.

format should be same as above pasted in question.
# 4  
Old 08-10-2014
Code:
awk '
$1~/solid/ {out=$2".stl"}
{print > out}
' file

This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script to Split matrix file with delimiter into multiple files

I have a large semicolon delimited file with thousands of columns and many thousands of line. It looks like: ID1;ID2;ID3;ID4;A_1;B_1;C_1;A_2;B_2;C_2;A_3;B_3;C_3 AA;ax;ay;az;01;02;03;04;05;06;07;08;09 BB;bx;by;bz;03;05;33;44;15;26;27;08;09 I want to split this table in to multiple files: ... (1 Reply)
Discussion started by: trymega
1 Replies

2. Shell Programming and Scripting

Shell Script:split the values

Hi, I have file like below as file.txt Linux sptpp1a 2.6.18 348.1.1.el5 xxxxx 05/02/2013 %usr %sys %wio %idle 14:18:30 0 1 0 99 14:18:40 1 1 0 98 14:18:50 1 1 0 98 14:19:00 ... (5 Replies)
Discussion started by: Mani_apr08
5 Replies

3. Shell Programming and Scripting

Backup script to split and tar files

Hi Guys, I'm very new to bash scripting. Please help me on this. I'm in need of a backup script which does the ff. 1. If a file is larger than 5GB. split it and tar the file. 2. Weekly backup file to amazon s3 using s3rsync 3. If a file is unchanged it doesn't need to copy to amazon s3 ... (4 Replies)
Discussion started by: ganitolngyundre
4 Replies

4. Shell Programming and Scripting

Split line to multiple files Awk/Sed/Shell Script help

Hi, I need help to split lines from a file into multiple files. my input look like this: 13 23 45 45 6 7 33 44 55 66 7 13 34 5 6 7 87 45 7 8 8 9 13 44 55 66 77 8 44 66 88 99 6 I want to split every 3 lines from this file to be written to individual files. (3 Replies)
Discussion started by: saint2006
3 Replies

5. Shell Programming and Scripting

Script to split text files

Hi All, I'm fairly new to scripting, so need a little help to get started with this problem. I don't mind whether I go for an awk/bash/other approach, I don't really know which would be best suited to the problem... Lets say I have a 10000 line text file, I would like to split this up into a... (6 Replies)
Discussion started by: phil8258
6 Replies

6. Shell Programming and Scripting

SPLIT STRING in bash shell script

i need one help.... if i have a string like aaaaa,bbbbb,ccccc,aaaaa How to to split the string and check howmany times aaaaa will be in that string? Thanks (7 Replies)
Discussion started by: karthinvk
7 Replies

7. Shell Programming and Scripting

AWK Shell Program to Split Large Files

Hi, I need some help creating a tidy shell program with awk or other language that will split large length files efficiently. Here is an example dump: <A001_MAIL.DAT> 0001 Ronald McDonald 01 H81 0002 Elmo St. Elmo 02 H82 0003 Cookie Monster 01 H81 0004 Oscar ... (16 Replies)
Discussion started by: mkastin
16 Replies

8. Shell Programming and Scripting

Help with Split shell script

Hi all, Following is the shell script which I am using for splitting the contents from a flat file to the multiple XMLs. The problem is that this script is working file when the input file is having 10000 lines. When the number of lines increases; the performance degrades drastically. Please... (1 Reply)
Discussion started by: amtrip
1 Replies

9. Shell Programming and Scripting

split files by specifying a string (bash shell)

Hi all, I have a file of around 300 lines in which string "SERVER" occurs around 32 times. for eg. I need to split files like, for eg I am using this code awk '/SERVER/{n++}{print > f n}' f=/vikas/list /vikas/final But the problem is that it makes maximum of 10 files, but I... (12 Replies)
Discussion started by: vikas027
12 Replies

10. Shell Programming and Scripting

Shell script to split XML file

Hi, I'm experiencing difficulty in loading an XML file to an Oracle destination table.I keep running into a memory problem due to the large size of the file. I want to split the XML file into several smaller files based on the keyword(s)/tags : '' and '' and would like to use a Unix shell... (2 Replies)
Discussion started by: bayflash27
2 Replies
Login or Register to Ask a Question