Hi Gurus
I have to split the incoming source file into multiple file.
File contains some unwanted XML tags also .
Files looks like
some XML tags
FILEHEADERABC 12
--
---
----
EOF
some xml tags
xxxFILEHEADERABC 13
--
---
----
EOF
I have to ignore XML tags and only split file based on FILEHEADER and EOF only and name each file like ABC_12.txt and ABC_13.txt. Similarly there are many messages in the file. I have to ignore all unwanted data before FILEHEADER and afetr EOF .
Please help
Try:
awk '/FILEHEADERABC/{n=$2}/FILEHEADERABC/,/EOF/{print > "ABC_"n".txt"}' file
Thanks for the reply....
Just to confirm , value of ABC can be any thing only FILEHEADER and EOF is fixed.
so to have the value of ABC in variable what needs to be done its of 5 characters in length
Try this then:
awk '/FILEHEADER/{a=$1;sub(".*FILEHEADER","",a);b=$2}/FILEHEADER/,/EOF/{print > a"_"b".txt"}' file
If there are many files we need to close the files. Also, not all awks write to a quoted string, they need the filename in a variable..
awk -FFILEHEADER '$0~FS{f=$2;sub(" ","_",f)} f{print>f} /EOF/{close(f);f=x}' infile
You can to use command "split", see "man split" to know parameters.