Split large xml into mutiple files and with header and footer in file


Login or Register to Reply

 
Thread Tools Search this Thread
# 15  
Old 2 Weeks Ago
Hello All.

Code:
$x =sampletest_110.xml
sampletest_111.xml

Command :
Code:
awk -f xml_String_split.awk -f xml_split.awk OUT=$x"" ROWS="500" $x $x

For the above its generating file names as below
Code:
sampletest_110.xml.0001
sampletest_111.xml.0001

when i use mv command to rename the files
I used below command to mv
Code:
for f in sampletest_*; do mv "$f" "${f/sampletest_/Extrfile}.xml";

Output file names:
Code:
Extrfile110.xml.0001.xml
Extrfile111.xml.0001.xml

Iam expecting filenames to be as below please help me to achieve below :
Code:
Extrfile110.xml
Extrfile111.xml

----


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

Last edited by RudiC; 2 Weeks Ago at 04:29 AM.. Reason: Added CODE tags.
# 16  
Old 2 Weeks Ago
I've got some difficilties understanding what you are trying to do, so maybe just some comments:


  • If you're trying to assign two lines to a variable with
    Code:
    $x =sampletest_110.xml
    sampletest_111.xml

    , you'll have a) a syntax error, b) a logical error and (probably) c) two "command not found" errors. Remove the $sign, the space, and quote the entire string
  • Code:
    awk -f xml_String_split.awk -f xml_split.awk OUT=$x"" ROWS="500" $x $x

    is a very strange construct. If I interpret it correctly, it will run the split script eight times: twice on the first file name in $x, twice on the second, and again for the second instance of $x. Is that what you want?
  • Code:
    for f in sampletest_*; do mv "$f" "${f/sampletest_/Extrfile}.xml";

    (A done is missing here!) You replace the "sampletest" string with "Extrfile", and append ".xml". The result is exactly that. You desired target will be achieved in multiple steps, like
    Code:
    for f in sampletest_*
      do    TMP="${f/sampletest_/Extrfile}"
            echo mv "$f" "${TMP%.*}"
      done


Last edited by RudiC; 2 Weeks Ago at 07:24 AM..
This User Gave Thanks to RudiC For This Post:
karthik (2 Weeks Ago)
# 17  
Old 2 Weeks Ago
In addition to what RudiC has already said, note that asking us to tell you why the command:
Code:
awk -f xml_String_split.awk -f xml_split.awk OUT=$x"" ROWS="500" $x $x

doesn't work without showing us your code contained in the files xml_split.awk and xml_String_split.awk is rather difficult.

My crystal ball isn't working well enough to spot your problems in these files this morning.
This User Gave Thanks to Don Cragun For This Post:
karthik (2 Weeks Ago)
# 18  
Old 2 Weeks Ago
Thanks Rudic it worked.

--- Post updated at 11:06 PM ---

Hi Rudic,

Need one more help I have a xml file with the below job_id repetition, for every response i get from service it will generate one job_id i will store that in a response.xml file
my requirement is to pick the job_id's and store it in a variable with comma seperator as the below format and pass that variable value to DB as input


Required output:
Code:
30537,30538,30539

XML :
Code:
JobUnique_Id><ns11:Job_Id>30537</ns11:Job_Id></ns6:JobResponse>
             <ns11:Job_Id>30538</ns11:Job_Id
             <ns11:Job_Id>30539</ns11:Job_Id

--- Post updated at 11:08 PM ---

Rudic reply helped me sorry for not briefing you the problem in detail.

Last edited by karthik; 2 Weeks Ago at 09:04 PM..
# 20  
Old 1 Week Ago
Hi Corona,

I have tried the below where as i can find job_id value when trying to replace the job_id values with comma seperator that new_var is blank kindly assist

Code:
JobId =$(cat Response.xml | awk -F"Job_Id>" '{print $2}' | awk -F"<" '{print $1}')
echo $JobId

JOB_ID output here is :12345
23415

Code:
NEW_VAR=$(echo $JobId | sed -e "s/^/'/" | sed -e "s/$/'/" | tr '\n' ',')

Output:12345,23415 is the expected output for the NEW_VAR
# 21  
Old 1 Week Ago
Hi karthik,
As usual, I seem to be lost again trying to understand what you are trying to do.
Quote:
Originally Posted by karthik
Hi Corona,

I have tried the below where as i can find job_id value when trying to replace the job_id values with comma seperator that new_var is blank kindly assist

Code:
JobId =$(cat Response.xml | awk -F"Job_Id>" '{print $2}' | awk -F"<" '{print $1}')
echo $JobId

JOB_ID output here is :12345
23415
With a <space> between the first word of the above command and the <equals-sign>, command runs a utility named JobId with one or more arguments (depending on the output from the two awk commands in your script) where the first argument's first character is the <equals-sign>. The echo command after that line will print an empty line unless JobId had been assigned a value somewhere else.

Furthermore, JOB_ID and JobId are not even close to being the same thing AND with no CODE tags I have no idea what value you are saying the output of that awk command was. And, since you haven't shown us any sample file named Response.xml we have no way of recreating the input you are feeding into that script to try it out ourselves.

Quote:
Originally Posted by karthik
Code:
NEW_VAR=$(echo $JobId | sed -e "s/^/'/" | sed -e "s/$/'/" | tr '\n' ',')

Output:12345,23415 is the expected output for the NEW_VAR
The echo of an unquoted variable expansion is only going to produce a single <newline> character at the end of the single line of output it produces; so you can't possibly want tr to change that <newline> character into a <comma>? And, you're invoking sed two more times to enclose your results in <single-quote>s, but you don't show any <single-quote>s in the expected output you say you want to store into the shell variable NEW_VAR. So, again, I'm very confused about how this code might be expected to produce the output you want.

Unless you want to run a loop processing the individual job IDs produce by the first awk script above, why not just have it print the results you want in the format in which you want them to be printed instead of producing output you don't want following by invoking four more utilities to reformat the output?

Making the wild assumption that the awk script you showed us produced two output lines with each containing a single Job ID and that you want to set NEW_VAR to a string containing just those two Job IDs separated by a <comma>, we should be able to produce aMUCH more efficient single awk command to produce the output you want to store into the variable NEW_VAR. But, of course, with no sample input to work with, I can't determine whether the script above that calls awk twice is expecting to find two Job IDs on a single line input file or is expecting to find one Job ID on each of two input lines. Therefore, I can't suggest an awk command that might work for you. Either way there is no need for two awk commands, two sed command, atr command, and two command substitutions.
This User Gave Thanks to Don Cragun For This Post:
Neo (1 Week Ago)
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Split large file into smaller files without disturbing the entry chunks Kamesh G UNIX for Beginners Questions & Answers 12 05-10-2018 05:39 AM
Eliminate Header and footer from EBCDIC file abhilashnair UNIX for Dummies Questions & Answers 4 12-18-2014 05:48 AM
File Row Line Count without Header Footer gagan8877 UNIX for Dummies Questions & Answers 7 05-02-2013 02:29 PM
Is there a way to append both at header and footer of a file jediwannabe Shell Programming and Scripting 3 02-28-2013 06:57 AM
Help needed - Split large file into smaller files based on pattern match frustrated1 Shell Programming and Scripting 7 01-18-2013 06:02 PM
Removing header or footer from file sridhardwh Shell Programming and Scripting 5 06-04-2012 06:43 AM
Add header and footer with record count in footer itsranjan Shell Programming and Scripting 1 03-25-2012 12:45 AM
Split large zone file dump into multiple files Bluemerlin Shell Programming and Scripting 7 12-21-2011 09:15 AM
sort a report file having header and footer suryanarayana Shell Programming and Scripting 4 11-25-2011 10:48 PM
Ignore Header and Footer and Sort the data in fixed width file sasikari Shell Programming and Scripting 5 07-14-2011 12:42 PM
Using AWK to separate data from a large XML file into multiple files JRy Shell Programming and Scripting 16 10-17-2009 09:06 PM
Split large file and add header and footer to each small files ashish4422 Shell Programming and Scripting 7 07-07-2008 03:13 PM
Split large file and add header and footer to each file ashish4422 Shell Programming and Scripting 1 04-15-2008 07:12 AM
Total of lines w/out header and footer incude for a file gzs553 Shell Programming and Scripting 1 11-16-2006 07:42 PM
Need to Chop Header and Footer record from input file coolbudy Shell Programming and Scripting 4 08-09-2005 01:26 PM