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


Login or Register to Reply

 
Thread Tools Search this Thread
# 15  
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; 02-07-2019 at 04:29 AM.. Reason: Added CODE tags.
# 16  
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; 02-07-2019 at 07:24 AM..
This User Gave Thanks to RudiC For This Post:
# 17  
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:
# 18  
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; 02-07-2019 at 09:04 PM..
# 20  
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  
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:
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
Is there a way to append both at header and footer of a file
jediwannabe
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...... Shell Programming and Scripting
3
Shell Programming and Scripting
Removing header or footer from file
sridhardwh
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.... Shell Programming and Scripting
5
Shell Programming and Scripting
Add header and footer with record count in footer
itsranjan
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...... Shell Programming and Scripting
1
Shell Programming and Scripting
Split large file and add header and footer to each small files
ashish4422
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?... Shell Programming and Scripting
7
Shell Programming and Scripting
Split large file and add header and footer to each file
ashish4422
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?... Shell Programming and Scripting
1
Shell Programming and Scripting

Featured Tech Videos