Sponsored Content
Top Forums Shell Programming and Scripting Split large xml into mutiple files and with header and footer in file Post 303030851 by Don Cragun on Monday 18th of February 2019 01:12:49 AM
Old 02-18-2019
Quote:
Originally Posted by karthik
Hi Don,

My Apologies for confusing you again AWK commands are perfectly working fine and it splits file correctly as expected

Hope I am not confusing you further

1) If my input file name is sampletest_111.xml after AWK command file name will be like sampletest_111.xml.0001
2)sampletest_111.xml.0001 is renamed to Extrfile111.xml
3)when there are multiple input files AWK is spliting files and creating unique files but
below piece of code is not renaming files in a sequence its just appending to 1 file
Output Expected:Extrfile111.xml,Extrfile1112.xml etc i mean unique name

... ... ...
Hi karthik,
I am not confused at all this time. Please go back and read closely what I said in post #28!

I don't care how well your awk script works when you invoke it with the name of a file to be processed. The script you showed us in post #27 NEVER EVER under any circumstances invokes awk; not even once! And, if your script doesn't run awk, it just plain is not possible that awk is splitting anything.

Showing us a few hundred more lines of awk code doesn't alter the fact that you are never running that code.

Until you alter the code that is initializing the FileList array correctly, there is nothing else to talk about. If you change the sixth line in your script from:
Code:
echo "$FileList"

to:
Code:
echo "Files to be processed: ${FileList[@]}"

and look at the output that line produces when you run your script, maybe you'll believe me. And, yes, I noticed that you changed the way you initialized that array from:
Code:
FileList=($(ls | grep "../Inbound/sampletest*\\_[0-9]"))

to:
Code:
FileList=($(ls | grep "sampletest*\\_[0-9]"))

but it doesn't alter the fact that the FileList array will still be an empty array and your awk script will never be executed. The empty line produced by the echo in your script should have been a strong indication to you that something was wrong, but you seem to be ignoring that fact. With the above change, hopefully it will be crystal clear.

The grep utility takes a basic regular expression as its first operand; not a filename matching pattern. BREs and filename matching patters have some similarities, but they are not the same. Since none of your filenames contain a literal backslash character (i.e. \), the grep can't match any lines in the output produced by ls.

You would do well to change the second line in your script from an empty line to:
Code:
set -xv

to enable tracing so you can actually see what your script is doing.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to Chop Header and Footer record from input file

Hi, I need to chope the header and footer record from an input file and make a new output file, please let me know how i can do it in unix.thanks. (4 Replies)
Discussion started by: coolbudy
4 Replies

2. Shell Programming and Scripting

Total of lines w/out header and footer incude for a file

I am trying to get a total number of tapes w/out headers or footers in a ERV file and append it to the file. For some reason I cannot get it to work. Any ideas? #!/bin/sh dat=`date +"%b%d_%Y"` + date +%b%d_%Y dat=Nov16_2006 tapemgr="/export/home/legato/tapemgr/rpts"... (1 Reply)
Discussion started by: gzs553
1 Replies

3. 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

4. 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

5. Shell Programming and Scripting

sort a report file having header and footer

I am having report file with header and footer . The details in between header and footer are separated by a pipe charater. I want to sort the file by considering multiple columns in between header and footer. pls help (4 Replies)
Discussion started by: suryanarayana
4 Replies

6. Shell Programming and Scripting

Add header and footer with record count in footer

This is my file(Target.txt) name|age|locaction abc|23|del xyz|24|mum jkl|25|kol The file should be like this 1|03252012 1|name|age|location 2|abc|23|del 2|xyz|24|mum 2|jkl|25|kol 2|kkk|26|hyd 3|4 Column 1 is row indicator for row 1 and 2, column indicator is 1,for data rows... (1 Reply)
Discussion started by: itsranjan
1 Replies

7. Shell Programming and Scripting

Removing header or footer from file

Hi Every one, what is the coomand to remove header or footer from a file. Please help me by providing command/syntax to remove header/footer from unix. Thanks in advance for all your support. (5 Replies)
Discussion started by: sridhardwh
5 Replies

8. Shell Programming and Scripting

Is there a way to append both at header and footer of a file

currently I've a file Insert into CD_CARD_TYPE (CODE, DESCRIPTION, LAST_UPDATE_BY, LAST_UPDATE_DATE) Values ('024', '024', 2, sysdate); Insert into CD_CARD_TYPE (CODE, DESCRIPTION, LAST_UPDATE_BY, LAST_UPDATE_DATE) Values ('032', '032', 2, sysdate); ........ is it... (3 Replies)
Discussion started by: jediwannabe
3 Replies

9. UNIX for Dummies Questions & Answers

File Row Line Count without Header Footer

Hi There! I am saving the file count of all files in a directory to an output file using: wc -l * > FileCount.txt I get: 114 G4SXORD 3 G4SXORH 0 G4SXORP 117 total But this count includes header and footer. I want to subtract 2 from the count and get ... (7 Replies)
Discussion started by: gagan8877
7 Replies

10. UNIX for Dummies Questions & Answers

Eliminate Header and footer from EBCDIC file

Is there any command to eliminate Header and footer from EBCDIC file (4 Replies)
Discussion started by: abhilashnair
4 Replies
All times are GMT -4. The time now is 07:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy