Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Splitting a file based on a pattern Post 302991784 by arunkumar_mca on Thursday 16th of February 2017 09:41:22 AM
Old 02-16-2017
Splitting a file based on a pattern

Hi All,

I am having a problem. I tried to extract the chunk of data and tried to fix I am not able to. Any help please

Basically I need to remove the for , values after K,

this is how it is now
Code:
A,,
B,
C,C,
D,D,
12/04/10,12/04/10,
K,1,1,1,1,0,3.0,
K,1,1,1,2,0,4.0,
K,1,1,2,1,0,3.0,
K,1,1,2,2,0,3.0,


And I want it to be like
Code:
A,,
B,
C,C,
D,D,
12/04/10,12/04/10,
K,1,1,1,0,3.0,
K,1,1,2,0,4.0,
K,1,2,1,0,3.0,
K,1,2,2,0,3.0,


I tried to split the file. But I think there will be a way to do that without splitting

Code:
grep K file >> newfile

and splitting the new file record by record and joining back



Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 02-16-2017 at 11:05 AM.. Reason: Changed QUOTE to CODE tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Splitting a file based on some condition and naming them

I have a file given below. I want to split the file where ever I came across ***(instead you can put ### symbols in the file) . Also I need to name the file by extracting the report name from the first line which is in bold(eg:RPT507A) concatinated with DD(day on which the file runs). Can someone... (1 Reply)
Discussion started by: srivsn
1 Replies

2. Shell Programming and Scripting

Splitting the file based on logic

Hello I have a requirement where i need to split the Input fixed width file which contains multiple invoices into multiple files with 2 invoices per file. Each invoice can be identified by its first line's second character which is "H" and sixth character is " " space and the invoice would... (10 Replies)
Discussion started by: dsdev_123
10 Replies

3. Shell Programming and Scripting

Splitting a file based on two patterns

Hi there, I've an input file as follows: *START 1001 a1 1002 a2 1003 a3 1004 a4 *END *START 1001 b1 1002 b2 1004 b4 *END *START 1001 c1 1004 c4 *END (6 Replies)
Discussion started by: kbirde
6 Replies

4. UNIX for Dummies Questions & Answers

Splitting a file based on first 8 chars

I have an input file of this format <Date><other data> For example, 20081213aaaaaaaaa 20081213bbbbbbbbb 20081220ccccccccc 20081220ddddddddd 20081220eeeeeeeee 20081227ffffffffffffff The first 8 chars are date in YYYYMMDD formT. I need to split this file into n files where n is the... (9 Replies)
Discussion started by: paruthiveeran
9 Replies

5. Shell Programming and Scripting

Splitting a file based on context.

I have file as shown below. Would like to split the file based on the context of data. Like, split the content between "---- XXX Info ----" and " ---- YYY Info ----" to a file. When I try using below command, 2nd file contains all the info starting after first "---- YYYY Info ----" instance.... (8 Replies)
Discussion started by: webkid
8 Replies

6. Shell Programming and Scripting

Splitting large file into multiple files in unix based on pattern

I need to write a shell script for below scenario My input file has data in format: qwerty0101TWE 12345 01022005 01022005 datainala alanfernanded 26 qwerty0101mXZ 12349 01022005 06022008 datainalb johngalilo 28 qwerty0101TWE 12342 01022005 07022009 datainalc hitalbert 43 qwerty0101CFG 12345... (19 Replies)
Discussion started by: jimmy12
19 Replies

7. Shell Programming and Scripting

Problem with splitting large file based on pattern

Hi Experts, I have to split huge file based on the pattern to create smaller files. The pattern which is expected in the file is: Master..... First... second.... second... third.. third... Master... First.. second... third... Master... First... second.. second.. second..... (2 Replies)
Discussion started by: saisanthi
2 Replies

8. Shell Programming and Scripting

Splitting file based on pattern and first character

I have a file as below pema.txt s2dhshfu dshfkdjh dshfd rjhfjhflhflhvflxhvlxhvx vlvhx sfjhldhfdjhldjhjhjdhjhjxhjhxjxh sjfdhdhfldhlghldhflhflhfhldfhlsh rjsdjh#error occured# skjfhhfdkhfkdhbvfkdhvkjhfvkhf sjkdfhdjfh#error occured# my requirement is to create 3 files frm the... (8 Replies)
Discussion started by: pema.yozer
8 Replies

9. Shell Programming and Scripting

Splitting textfile based on pattern and name new file after pattern

Hi there, I am pretty new to those things, so I couldn't figure out how to solve this, and if it is actually that easy. just found that awk could help:(. so i have a textfile with strings and numbers (originally copy pasted from word, therefore some empty cells) in the following structure: SC... (9 Replies)
Discussion started by: luja
9 Replies

10. Shell Programming and Scripting

Splitting a file into 4 files containing the same name pattern

Hello, I have one file which is in size around 20 MB , wanted to split up into four files of each size of 5 MB. ABCD_XYZ_20130302223203.xml. Requirement is that to write script which should do as : first three file should be of size 5 MB each, the fourth one content should be in the last... (8 Replies)
Discussion started by: ajju
8 Replies
AFREADMISC(3)															     AFREADMISC(3)

NAME
afReadMisc, afWriteMisc, afSeekMisc - access miscellaneous metadata in an audio file SYNOPSIS
#include <audiofile.h> int afReadMisc (AFfilehandle file, int miscid, void *buffer, int nbytes); int afWriteMisc (AFfilehandle file, int miscid, const void *buffer, int nbytes); int afSeekMisc (AFfilehandle file, int miscid, int offbytes); DESCRIPTION
afReadMisc reads up to nbytes from the miscellaneous data chunk identified by miscid in file. afWriteMisc writes up to nbytes to the miscellaneous data chunk identified by miscid in file. afSeekMisc changes the current offset within the miscellaneous data chunk identified by miscid to the offset offbytes. RETURN VALUE
afReadMisc returns the number of bytes read from the specified miscellaneous chunk into the buffer referred to by buffer. afWriteMisc returns the number of bytes written to the specified miscellaneous chunk from the buffer referred to by buffer. afSeekMisc returns the new location of the logical data pointer as measured as an offset in bytes from the beginning of the miscellaneous chunk's data area. ERRORS
afReadMisc, afWriteMisc, and afSeekMisc can produce the following error codes: o AF_BAD_READ o AF_BAD_WRITE o AF_BAD_MISCSEEK o AF_BAD_MISCID o AF_BAD_TRACKID o AF_BAD_FILEHANDLE AUTHOR
Michael Pruett <michael@68k.org> Audio File Library 0.3.6 03/06/2013 AFREADMISC(3)
All times are GMT -4. The time now is 01:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy