awk file split


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk file split
# 15  
Old 01-24-2014
Quote:
Originally Posted by f0usk4s
I think I expressed myself clearly
Far from it.

Nothing in your first post states that the element names are dummy placeholders.

Nothing in your first post specifies which elements to print. Knowing nothing about your real data, after looking at your original data sample, it is reasonable to assume that only the first three elements are relevant.

Even after your subsequent elaborations, the situation remains unclear. I have no idea if you want to print a fixed number of leading, numerically-valued elements. Or, if you want to print a variable number of leading, numerically-valued elements until the occurrence of a non-numerically valued element. Or perhaps you want to print all numerically-valued elements, ignoring any interleaved non-numerically valued elements. Or is it something else?

With those questions clearly answered, we would still not know what exactly is a numerically-valued element. From your original sample data, a reasonable method might test for the presence of a non-digit, e.g. [^0-9] or [^[:digit:]]. However, that reasonable method would fail with the data that you provided in post #13, due to the presence of at least one blank character (of which none are present in the original post's element values):

Quote:
Originally Posted by f0usk4s
Code:
<ISTITUTO>01 </ISTITUTO>

I have no doubt that I could have coded and tested a solution in less time than it took me to explain the ambiguities in your problem statement. Being specific, explicit, and providing actual data whenever possible is the best way to not waste anyone's time (including your own).

Regarding the file splitting problem itself, the simplest approach would be to not accumulate data in memory (as I believe all the suggestions in this thread do). Simply print relevant elements as they're read to a temp file. When the end of the record is reached, the permanent filename will have been constructed and mv can rename the temp file.

Regards,
Alister
# 16  
Old 01-24-2014
you are right, after reviewing all the posts I did not expressed myself clearly and I sincerely apologize for the inconvenience.
This User Gave Thanks to f0usk4s For This Post:
# 17  
Old 01-24-2014
Quote:
Originally Posted by f0usk4s
you are right, after reviewing all the posts I did not expressed myself clearly and I sincerely apologize for the inconvenience.
Good you realized.
# 18  
Old 01-24-2014
Quote:
Posted by f0usk4s:
you are right, after reviewing all the posts I did not expressed myself clearly and I sincerely apologize for the inconvenience.
It's not a problem f0usk4s we are here to help. But if you will be clear in your query then we can save our valueable time.

Thanks,
R. Singh
# 19  
Old 01-24-2014
Just to close this topic, I've gone with the solution of grep of the tag i wanted to search and using temp files and was able to receive the result I needed.

Thank you all for the help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Split file using awk

I need to split the incoming source file in to multiple files using awk. Split position is (6,13) : 8 positions All the records that are greater than 20170101 and less than or equal to 20181231 should go in a split file with file name as source... (11 Replies)
Discussion started by: rosebud123
11 Replies

2. Shell Programming and Scripting

Split File by Pattern with File Names in Source File... Awk?

Hi all, I'm pretty new to Shell scripting and I need some help to split a source text file into multiple files. The source has a row with pattern where the file needs to be split, and the pattern row also contains the file name of the destination for that specific piece. Here is an example: ... (2 Replies)
Discussion started by: cul8er
2 Replies

3. Shell Programming and Scripting

Split a file with awk

Hi! I have a file like this: a,b,c,12,d,e a,b,c,13,d,e a,b,c,14,d,e a,b,c,15,d,e a,b,c,16,d,e a,b,c,17,d,e I need to split that file in two: If field 4 is equal or higher than 14 that row goes to one file and if it is equal or higher than 15 to another. Can anyone point me in the... (2 Replies)
Discussion started by: Tr0cken
2 Replies

4. Shell Programming and Scripting

AWK File Split

Hi All, Input.txt XYZONEABC                  CZXTWOJJJ KKKSIXOOO asdfhajlsdhfajs asdfasfasdf Output Files: ONE.txt XYZONEABC                 TWO.txt CZXTWOJJJ SIX.txt KKKSIXOOO I had a script (2 Replies)
Discussion started by: kmsekhar
2 Replies

5. Shell Programming and Scripting

How to split a file using AWK?

Hello, I have a file like the following: david,a,b,c,20,r thomas,a,b,c,30,r willaiam,a,b,c,80,r barbara,a,b,c,100,r I would like to split the file into other files using a condition for the contents of column 5. The condition should be a if the contents of column 5 is in a range... (4 Replies)
Discussion started by: keenboy100
4 Replies

6. Shell Programming and Scripting

split a file using awk

Hi , I just need to split a file and outputfiles are redirected to gzip file need: Input file - A.gz content of A.gz is 100|sfdds|dffdds|200112|sdfdf 100|sfdds|dffdds|200112|sdfdf 100|sfdds|dffdds|200112|sdfdf 100|sfdds|dffdds|200212|sdfdf 100|sfdds|dffdds|200212|sdfdf... (3 Replies)
Discussion started by: mohan_xunil
3 Replies

7. Shell Programming and Scripting

awk - split file

How can I split a text file (in awk) in n others with number of record given in input? Thanks (6 Replies)
Discussion started by: pinguc
6 Replies

8. Shell Programming and Scripting

split file with awk

I did a lot of search on this forum on spiting file; found a lot, but my requirement is a bit different, please guide. Master file: x:start:5 line1:23 line2:12 2:90 x:end:5 x:start:2 45:56 22:90 x:end:2 x:start:3 line1:23 line2:12 x:end:3 x:start:2 line5:23 (1 Reply)
Discussion started by: uwork72
1 Replies

9. UNIX for Dummies Questions & Answers

Split a file with no pattern -- Split, Csplit, Awk

I have gone through all the threads in the forum and tested out different things. I am trying to split a 3GB file into multiple files. Some files are even larger than this. For example: split -l 3000000 filename.txt This is very slow and it splits the file with 3 million records in each... (10 Replies)
Discussion started by: madhunk
10 Replies

10. Shell Programming and Scripting

Split file using awk

I am trying to read a file and split the file into multiple files. I need to create new files with different set of lines from the original file. ie, the first output file may contain 10 lines and the second 100 lines and so on. The criteria is to get the lines between two lines starting with some... (8 Replies)
Discussion started by: pvar
8 Replies
Login or Register to Ask a Question