Sponsored Content
Top Forums Shell Programming and Scripting Sort and Split file with header and custom name Post 302957073 by Saanvi1 on Tuesday 6th of October 2015 04:32:58 PM
Old 10-06-2015
Thank you for the response. I tried the code below:
Code:
{
        { readlink /proc/$$/fd/0; line; sort; } | awk '
        NR==1           {OF=$0
                         next
                        }    
        NR==2           {HD=$0
                         next
                        }
        !((NR-3)%lines) {if (OF) close (OF)
                         sub (/(__[0-9])*\./, "__" ++CNT ".", OF)
                         print HD > OF
                        }
                        {print $0 > OF
                        }
        ' lines=30000
} < ${NEW_FILE}/MasterFile-HP-import-20151006.txt

But getting the error below:
readlink: not found
awk: syntax error near line 8
awk: bailing out near line 8


Also tried this:
Code:
awk '
NR==1           {HD=$0
                 OF=FILENAME
                 next
                }
!((NR-2)%lines) {if (OF) close (OF)
                 sub (/(__[0-9])*\./, "__" ++CNT ".", OF)
                 print HD > OF
                }
                {print $0 > OF
                }
' lines=30000 ${NEW_FILE}/MasterFile-HP-import-20151006.txt

Getting error:
awk: syntax error near line 6
awk: bailing out near line 6

Last edited by Saanvi1; 10-06-2015 at 05:38 PM.. Reason: Adding more statements
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split large file and add header and footer to each file

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? (1 Reply)
Discussion started by: ashish4422
1 Replies

2. UNIX for Dummies Questions & Answers

Sort a tab file with header.

How to sort a tab delimited file first on col1 and then on col2. Also I need to keep the header intact. file.txt val1 val2 val3 val4 a b c d m n o p e f g h i j k l ... (3 Replies)
Discussion started by: mary271
3 Replies

3. UNIX for Dummies Questions & Answers

Split a file and give custom names

Hello, I want to split a file based on an input list file that contains the lines each split should have + a corresponding file name. #!/bin/sh # sed -n 'start_line_#,end_line_#p' my_input_file > lines_extracted_output_file while read a b c do sed -n '$a,$bp' myLarge.file > $c.split... (2 Replies)
Discussion started by: Gussifinknottle
2 Replies

4. Shell Programming and Scripting

Split and add header and trailer from input file

I need to split the file based on pattern from position 34-37 while retaining the header and trailer records in each individual split file Also is it possible to output the TOM and PAT records in the same output file ? I need the output file names same as xyz_pattern_Datetimestamp.txt ... (23 Replies)
Discussion started by: techedipro
23 Replies

5. UNIX for Dummies Questions & Answers

Sort a las file keep the header as it is

I have several las files with a header and each file start Version and text and before the data starts end up with ~Ascii, then the numbers starts: ------------------------------------------------------------------------- Code: ~Version .....text.... ~Ascii 2 abc 230 1 name 1 abc ... (1 Reply)
Discussion started by: tk2000
1 Replies

6. UNIX for Dummies Questions & Answers

Sort a las file keep the header as it is

I have several las files with a header and each file start Version and text and before the data starts end up with ~Ascii, then the numbers starts: ------------------------------------------------------------------------- ~Version .....text.... ~Ascii 2 abc 230 1 name 1 abc 400 1... (17 Replies)
Discussion started by: tk2000
17 Replies

7. Shell Programming and Scripting

Split a file based on encountering header

I need to split a file based on headers found Input file file1 content: ADD john mickey DROP matt sam output of file F1 john mickey output of file F2 matt sam (5 Replies)
Discussion started by: Diddy
5 Replies

8. Shell Programming and Scripting

Split file by column value, each with header

Hello all, I have a csv with with different testcase values in column 5. year,min,max,Instrument,Testcase 2016,201,1003,GEOTROPH-02116,TATA7980 2016,53,1011,GEOTROPH-01963,TATA7980 2016,3,1024,GEOTROPH-02067,TATA7980 2016,203,1027,GEOTROPH-02011,TATA7980... (16 Replies)
Discussion started by: senhia83
16 Replies

9. UNIX for Beginners Questions & Answers

How do I custom sort the files in a directory using the filenames in a text file.?

Hi all, (5 Replies)
Discussion started by: KMusunuru
5 Replies

10. Shell Programming and Scripting

Sort file data according to a custom list of string

I have a string of pre defined ip address list which will always remain constant their order will never change like in below sample: iplist=8.8.5.19,9.7.5.14,12.9.9.23,8.8.8.14,144.1.113 In the above example i m considering only 5 ips but there could be many more. Now i have a file which... (15 Replies)
Discussion started by: mohtashims
15 Replies
UUENCODE(5)							File Formats Manual						       UUENCODE(5)

NAME
uuencode - format of an encoded uuencode file DESCRIPTION
Files output by uuencode(1C) consist of a header line, followed by a number of body lines, and a trailer line. Uudecode(1C) will ignore any lines preceding the header or following the trailer. Lines preceding a header must not, of course, look like a header. The header line is distinguished by having the first 6 characters "begin ". The word begin is followed by a mode (in octal), and a string which names the remote file. A space separates the three items in the header line. The body consists of a number of lines, each at most 62 characters long (including the trailing newline). These consist of a character count, followed by encoded characters, followed by a newline. The character count is a single printing character, and represents an inte- ger, the number of bytes the rest of the line represents. Such integers are always in the range from 0 to 63 and can be determined by sub- tracting the character space (octal 40) from the character. Groups of 3 bytes are stored in 4 characters, 6 bits per character. All are offset by a space to make the characters printing. The last line may be shorter than the normal 45 bytes. If the size is not a multiple of 3, this fact can be determined by the value of the count on the last line. Extra garbage will be included to make the character count a multiple of 4. The body is terminated by a line with a count of zero. This line consists of one ASCII space. The trailer line consists of "end" on a line by itself. SEE ALSO
uuencode(1C), uudecode(1C), uusend(1C), uucp(1C), mail(1) 7th Edition May 15, 1985 UUENCODE(5)
All times are GMT -4. The time now is 04:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy