Sponsored Content
Top Forums Shell Programming and Scripting How to split this txt file into small files? Post 302840095 by psychmyluo on Sunday 4th of August 2013 12:30:58 PM
Old 08-04-2013
Hi

Thank you for your generous help! I am sorry that I did not make it clear. The original post may difficult to understand. So, I made some changes. I make the file into four columns like this:

Code:
name	Onsetime	duration	weight
s002_run1_fng	122.6 	2	1
s002_run1_fng	144.8 	2	1
s002_run1_fyg	132.6 	2	1
s002_run1_fyg	182.6 	2	1
s002_run1_fyg	198.6 	2	1
s002_run1_fyg	230.6 	2	1
s002_run1_fyg	308.6 	2	1
s002_run1_fyg	368.6 	2	1
s002_run1_fyg	382.6 	2	1
s002_run1_fyg	410.6 	2	1
s002_run1_fnl	294.8 	2	1
s002_run1_fnl	394.8 	2	1
s002_run1_fyl	66.6 	2	1
s002_run1_fyl	78.6 	2	1
s002_run1_fyl	158.6 	2	1
s002_run1_fyl	207.1 	2	1
s002_run1_fyl	257.4 	2	1
s002_run1_fyl	269.2 	2	1
s002_run1_fyl	319.2 	2	1
s002_run1_fyl	327.3 	2	1
s002_run1_fnn	52.8 	2	1
s002_run1_fnn	280.7 	2	1
s002_run1_fnn	350.8 	2	1
s002_run1_fyn	96.6 	2	1
s002_run1_fyn	110.6 	2	1
s002_run1_fyn	169.3 	2	1

I also attached the file. I would like to split the file into new txt files, the first column will be the name of the new file, and the second to the fourth column is the content of the new file. If the first column is the same, the second to the fourth column will be composed a new file. For example, the first file I want to is
Code:
122.6 	2	1
144.8 	2	1

and the new file name would be "s002_run1_fng"

How to code using shell ?

Thank you! Your help is greatly appreciated!


feedback.txt

Last edited by psychmyluo; 08-04-2013 at 05:39 PM.. Reason: Add CODE tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

small script - get sql output & write into txt

Hi, how can I write a small script to run the following statement and output the result into check_result.txt select /*+RULE*/ tapname from typetbl where tapname like 'AA%' and rejectcode=9; Normally, I just type sql and get into SQL> (2 Replies)
Discussion started by: happyv
2 Replies

2. Shell Programming and Scripting

Split a file into 16 small files

Hi I want to split a file that has 'n' number of records into 16 small files. Can some one suggest me how to do this using Unix script? Thanks rrkk (10 Replies)
Discussion started by: rrkks
10 Replies

3. Shell Programming and Scripting

Split large file and add header and footer to each small files

I have one large file, after every 200 line i have to split the file and the add header and footer to each small file? It is possible to add different header and footer to each file? (7 Replies)
Discussion started by: ashish4422
7 Replies

4. UNIX for Dummies Questions & Answers

How to split a huge file into small pieces (per 2000 columns)?

Dear all, I have a big file:2879(rows)x400,170 (columns) like below. I 'd like to split the file into small pieces:2879(rows)x2000(columns) per file (the last small piece will be 2879x170. So far, I only know how to create one samll piece at one time. But actually I need to repeat this work... (6 Replies)
Discussion started by: forevertl
6 Replies

5. Shell Programming and Scripting

KSH script for split a txt file

I have a problem which I would like to solve by using UNIX power and inspired minds around world. Here is the problem I have a text file and it has data as follows 1X.....................1234567890123456789T1234598765XT1 (header) 1Z01............(sub HEADER) P100001............ Q1........... (4 Replies)
Discussion started by: ask.chowhan
4 Replies

6. Solaris

How to split 10GB file into small Sizes

Hi Team I have one 10 Gb log file I want to split it into say 10 of 1-1Gb file pls share ur experiences how to do this? Thanks in advance, (3 Replies)
Discussion started by: zimmyyash
3 Replies

7. Shell Programming and Scripting

Split a large array into small chunks

Hi, I need to split a large array "@sharedArray" into 10 small arrays. The arrays should be like @sharedArray1,@sharedArray2,@sharedArray3...so on.. Can anyone help me with the logic to do so :(:confused: (6 Replies)
Discussion started by: rkrish
6 Replies

8. UNIX for Dummies Questions & Answers

Split Every Line In Txt Into Separate Txt File, Named Same As The Line

Hi All Is there a way to export every line into new txt file where by the title of each txt output are same as the line ? I have this txt files containing names: Kandra Vanhooser Rhona Menefee Reynaldo Hutt Houston Rafferty Charmaine Lord Albertine Poucher Juana Maes Mitch Lobel... (2 Replies)
Discussion started by: Nexeu
2 Replies

9. UNIX for Beginners Questions & Answers

Split a txt file on the basis of line number

I have to split a file containing 100 lines to 5 files say from lines ,1-20 ,21-30 ,31-40 ,51-60 ,61-100 Here is i can do it for 2 file but how to handle it for more than 2 files awk 'NR < 21{ print >> "a"; next } {print >> "b" }' $input_file Please advidse. Thanks (4 Replies)
Discussion started by: abhaydas
4 Replies

10. UNIX for Beginners Questions & Answers

Split large file into 24 small files on one hour basis

I Have a large file with 24hrs log in the below format.i need to split the large file in to 24 small files on one hour based.i.e ex:from 09:55 to 10:55,10:55-11:55 can any one help me on this.! ... (20 Replies)
Discussion started by: Raghuram717
20 Replies
UNSHAR(1)						      General Commands Manual							 UNSHAR(1)

NAME
unshar - unpack a shar file SYNOPSIS
unshar [ options ] [ file ... ] DESCRIPTION
Unshar scans mail messages looking for the start of a shell archive. It then passes the archive through a copy of the shell to unpack it. It will accept multiple files. If no files are given, standard input is used. OPTIONS
Options have a one letter version starting with - or a long version starting with --. The exception is --help and --version, which does not have a short version. --version Print the version number of the program on standard output, then immediately exits. --help Print a help summary on standard output, then immediately exits. -d DIRECTORY --directory=DIRECTORY Change directory to DIRECTORY before unpacking any files. -c --overwrite Passed as an option to the shar file. Many shell archive scripts (including those produced by `shar' 3.40 and newer) accepts a -c argument to indicate that existing files should be overwritten. -e --exit-0 This option exists mainly for people who collect many shell archives into a single mail folder. With this option, `unshar' isolates each different shell archive from the others which have been put in the same file, unpacking each in turn, from the beginning of the file towards its end. Its proper operation relies on the fact that many shar files are terminated by a `exit 0' at the beginning of a line. Option -e is internally equivalent to -E "exit 0". -E STRING --split-at=STRING This option works like -e, but it allows you to specify the string that separates archives if `exit 0' isn't appropriate. For example, noticing that most `.signatures' have a `--' on a line right before them, one can sometimes use `--split-at=--' for splitting shell archives which lack the `exit 0' line at end. The signature will then be skipped altogether with the headers of the following message. -f --force The same as -c. SEE ALSO
shar(1) DIAGNOSTICS
Any message from the shell may be displayed. AUTHORS
The shar and unshar programs is the collective work of many authors. Many people contributed by reporting problems, suggesting various improvements or submitting actual code. A list of these people is in the THANKS file in the sharutils distribution. September 10, 1995 UNSHAR(1)
All times are GMT -4. The time now is 11:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy