Separating Pattern Into Separate Files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Separating Pattern Into Separate Files
# 15  
Old 09-28-2010
Quote:
Originally Posted by Double-E
19. do N=$(echo $L | grep -E '^(VTZ|NYZ)[0-9]+') && { F=$N; echo $F :>${F}; }
Would go better with the ';'
19. do N=$(echo $L | grep -E '^(VTZ|NYZ)[0-9]+') && { F=$N; echo $F; :>${F}; }[/B]
# 16  
Old 09-28-2010
Code:
awk '/^(NYZ|VTZ)/{n=$1}n{print >n}$1=="$$"{n=x}' infile

# 17  
Old 09-28-2010
Hello - thanks again for the help:

Frans - I made your change and now I am getting an error on the next line:

line 5: syntax error near unexpected token `done'
  1. <LI style="VERTICAL-ALIGN: top; FONT-WEIGHT: normal">while read L
    <LI style="VERTICAL-ALIGN: top; FONT-WEIGHT: normal">do
    <LI style="VERTICAL-ALIGN: top; FONT-WEIGHT: normal"> N=$(echo $L | grep -E '^(VTZ|NYZ)[0-9]+') && { F=$N; :>${F;} }
    <LI style="VERTICAL-ALIGN: top; FONT-WEIGHT: normal">echo $L >> $F
  2. done < infile
Scrutinizer - I typed in your line of code and it did nothing. Is that supposed to be a csh or sh file?

---------- Post updated at 03:49 PM ---------- Previous update was at 03:47 PM ----------

Oops, sorry about that code Frans. The done < infile line gives me the following error:

syntax error near unexpected token `done'
# 18  
Old 09-28-2010
Neither, it is awk. It give no output on the command line, but it should produce output files. Did you check if they are present, using ls -ltr?
Otherwise are you on Solaris? use nawk instead of /usr/xpg4/bin/awk

Perhaps this would work:
Code:
awk '!/\$/{print $0 ORS ORS "$$">$1}' RS= infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] Pattern match and write to separate files

I need to parse a file and depending on a patern match(in the insert job line) separate files have to be created with a line added (content in file2). Mapping for pattern match and add line : for Alpha 123 for Beta 234 for Gamma 345 no match (goes into another file) File 1 ... (3 Replies)
Discussion started by: w020637
3 Replies

2. Shell Programming and Scripting

How to generate a csv files by separating the values from the input file based on position?

Hi All, I need help for doing the following. I have a input file like: aaaaaaaaaabbbbbbbbbbbbbbbbbbbb cccbbbbbaaaaaadddddaaaabbbbbbb now I am trying to generate a output csv file where i will have for e.g. 0-3 chars of each line as the first column in the csv, 4-10 chars of the line as... (3 Replies)
Discussion started by: babom
3 Replies

3. Programming

Separating two classes in two files

I have a file Map.hh shown below. I want to put the two classes Phase and Map in two different files Phase.hh and Map.hh. I have forward declaration before the Map class. How can I tackle this situation? ////////////////////////////////////////////////////////////////////////// #ifndef... (3 Replies)
Discussion started by: kristinu
3 Replies

4. Shell Programming and Scripting

Separating list of input files (*.file) with a comma in bash script

Hi all, I'm trying to get a bash script working for a program (bowtie) which takes a list of input files (*.fastq) and assembles them to an output file (outfile.sam). All the .fastq files are in one folder in my home directory (~/infiles). The problem is that the 'bowtie' requires that... (7 Replies)
Discussion started by: TuAd
7 Replies

5. Shell Programming and Scripting

Find required files by pattern in xml files and the change the pattern on Linux

Hello, I need to find all *.xml files that matched by pattern on Linux. I need to have written the file name on the screen and then change the pattern in the file just was found. For instance. I can start the script with arguments for keyword and for value, i.e script.sh keyword... (1 Reply)
Discussion started by: yart
1 Replies

6. Shell Programming and Scripting

Separating delimited file by pattern with exclusion list

I have a file with the contents below jan_t=jan;feb_t=feb;mar_t=mar;year=2010 jan_t=null;feb_t=feb;mar_t=mar;year=2010 jan_t=jan;feb_t=feb;mar_t=mar;year=2010 I want to extract out all the fields values ending with "_t" , however, i want to exclude feb_t and mar_t from the results In... (6 Replies)
Discussion started by: alienated
6 Replies

7. Shell Programming and Scripting

Merging files into a single tab delimited file with a space separating

I have a folder that contains say 50 files in a sequential order: cdf_1.txt cdf_2.txt cdf_3.txt cdf_3.txt . . . cdf_50.txt. I need to merge these files in the same order into a single tab delimited file. I used the following shell script: for x in {1..50}; do cat cdf_${x}.txt >>... (3 Replies)
Discussion started by: Lucky Ali
3 Replies

8. UNIX for Dummies Questions & Answers

Simple script for separating files

Hi all, I was wondering if someone could help me writing a simple script on separating files into separate folders. I have 92 files called various things and I want to separate these folders like so: Create a folder called "1" and put files 1-23 in it Create a folder called "2" and put... (5 Replies)
Discussion started by: hertingm
5 Replies

9. Shell Programming and Scripting

extract x lines after a pattern - place each result in separate file

Hi all, I have many files that have 1 or more occurrences of the information I want. There are two distinct sets of information. I want get this info and place each occurrence in its own file. The 3 lines before one set are this grid 00 01 02 16 17 18 **40 lines of code I want to... (5 Replies)
Discussion started by: gobi
5 Replies

10. Shell Programming and Scripting

to separate a specific pattern

Hi friends, I have a file with following pattern. OBJECT TYPE="locale", NAME=locale_nl_NL, UNIQUE_FIELD=win32_lcid FIELDS clarify_lang = 0; END_FIELDS END_OBJECT NAME=locale_nl_NL OBJECT TYPE="locale", NAME=locale_nl_BE UNIQUE_FIELD=win32_lcid FIELDS iso_cntry =... (11 Replies)
Discussion started by: shriashishpatil
11 Replies
Login or Register to Ask a Question