AWK File Split

Hi All,

[LEFT]Input.txt

XYZONEABC 
CZXTWOJJJ
KKKSIXOOO
asdfhajlsdhfajs
asdfasfasdf

[LEFT]Output Files:

ONE.txt
XYZONEABC 
 
TWO.txt
CZXTWOJJJ
 
SIX.txt
KKKSIXOOO

[LEFT]I had a script
File.awk

awk '!/^$/{
a=substr($0,3,3)
print $0 > a".txt"
}' Input.txt

[LEFT]above script will use the substr and split the data accordingly..
I need to fetch only ONE,TWO,SIX records and i need to get only three files(ONE.txt, TWO.txt, SIX.txt) always i need to fetch these files only on every run i need to ignore other records..[/LEFT]

Thanks

[/FONT][/FONT]

awk '!/^$/{
  a=substr($0,3,3)
  if (a == "ONE" || a == "TWO" || a == "SIX")
    print $0 > a".txt"
}' Input.txt

---------- Post updated at 12:48 PM ---------- Previous update was at 12:42 PM ----------

Well, also with your sample input the substr should be substr($0,4,3). awk starts at 1. character 4 is where "ONE"/"TWO"/"SIX" begin...

1 Like

Thanks working fine....