Code Comments
Programming Forum and web based access to our favorite programming groups.Hello Folks, I am totally newbie on AWK programming and I need to use this tool for a windows text file conversion in a DOS batch file. I need to break the line every time the ";" symbol appears. As the follow example: Normal text: "ForegroundApplicationBoost"="2";"BootDevice"="\\Device\\HarddiskDmVolumes\\ Ft3300Dg0\\Volume1";"BuildNumber"="3790";"FreeSpaceInPagingFiles"="3672612"; "CSName"="FT3300";"Caption"="Microsoft(R) Windows(R) Server 2003, Enterprise Edition";"CodeSet"="1252"; Text after AWK ForegroundApplicationBoost"="2"; "BootDevice"=" \\Device\\HarddiskDmVolumes\\Ft3300Dg0\\ Volume1"; "BuildNumber"="3790"; "FreeSpaceInPagingFiles"="3672612"; "CSName"="FT3300" "Caption"="Microsoft(R) Windows(R) Server 2003, Enterprise Edition"; "CodeSet"="1252"; I need to create a new text file after the conversion without modify the original source. Is it possible? (Normal file > AWK > New file with break lines). How do I program this?? Thank a lot! Andre
Post Follow-up to this messageBlackSun napisaĆ(a):
> I need to break the line every time the ";" symbol appears. As the
> follow example:
>
> Normal text:
> "ForegroundApplicationBoost"="2";"BootDevice"="\\Device\\HarddiskDmVolumes
\\Ft3300Dg0\\Volume1";"BuildNumber"="3790";"FreeSpaceInPagingFiles"="3672612
";"CSName"="FT3300";"Caption"="Microsoft(R)
> Windows(R) Server 2003, Enterprise Edition";"CodeSet"="1252";
>
> Text after AWK
> ForegroundApplicationBoost"="2";
> "BootDevice"=" \\Device\\HarddiskDmVolumes\\Ft3300Dg0\\
Volume1";
> "BuildNumber"="3790";
> "FreeSpaceInPagingFiles"="3672612";
> "CSName"="FT3300"
> "Caption"="Microsoft(R) Windows(R) Server 2003, Enterprise Edition";
> "CodeSet"="1252";
>
awk '{ gsub(/;/, ";\x0D\x0A" ); print}'
np.
echo " ala;ola;lola;ela;" | awk '{ gsub(/;/, ";\x0D\x0A" ); print}'
ala;
ola;
lola;
ela;
Problem is ... echo " ola; lola ; 'it;is;one;string'; ala "
....
it;
is;
...
Koriolan
Post Follow-up to this messageBlackSun wrote: <snip> > I need to break the line every time the ";" symbol appears. As the > follow example: > > Normal text: > "ForegroundApplicationBoost"="2";"BootDevice"="\\Device\\HarddiskDmVolumes \\Ft3300Dg0\\Volume1";"BuildNumber"="3790";"FreeSpaceInPagingFiles"="3672612 ";"CSName"="FT3300";"Caption"="Microsoft(R) > Windows(R) Server 2003, Enterprise Edition";"CodeSet"="1252"; > > Text after AWK > ForegroundApplicationBoost"="2"; > "BootDevice"=" \\Device\\HarddiskDmVolumes\\Ft3300Dg0\\ Volume1"; > "BuildNumber"="3790"; > "FreeSpaceInPagingFiles"="3672612"; > "CSName"="FT3300" > "Caption"="Microsoft(R) Windows(R) Server 2003, Enterprise Edition"; > "CodeSet"="1252"; > > I need to create a new text file after the conversion without modify > the original source. awk does not modify the original source unless you write specific code to make that happen. Is it possible? (Normal file > AWK > New file > with break lines). > > How do I program this?? gawk -vRS=";" -vORS=";\n" '1' infile > outfile e.g.: PS1> printf "a;b;c;" | gawk -vRS=";" -vORS=";\n" '1' a; b; c; You will have to deal with newlines or linefeeds if present in your input file and you don't want them in the output file. Ed.
Post Follow-up to this messageBEGIN { FS=";"
OFS=";\n"
ORS=""
}
{ $1=$1; print }
Post Follow-up to this messageBlackSun wrote: <snip> > I need to break the line every time the ";" symbol appears. As the > follow example: > > Normal text: > "ForegroundApplicationBoost"="2";"BootDevice"="\\Device\\HarddiskDmVolumes \\Ft3300Dg0\\Volume1";"BuildNumber"="3790";"FreeSpaceInPagingFiles"="3672612 ";"CSName"="FT3300";"Caption"="Microsoft(R) > Windows(R) Server 2003, Enterprise Edition";"CodeSet"="1252"; > > Text after AWK > ForegroundApplicationBoost"="2"; > "BootDevice"=" \\Device\\HarddiskDmVolumes\\Ft3300Dg0\\ Volume1"; > "BuildNumber"="3790"; > "FreeSpaceInPagingFiles"="3672612"; > "CSName"="FT3300" > "Caption"="Microsoft(R) Windows(R) Server 2003, Enterprise Edition"; > "CodeSet"="1252"; > > I need to create a new text file after the conversion without modify > the original source. awk does not modify the original source unless you write specific code to make that happen. Is it possible? (Normal file > AWK > New file > with break lines). > > How do I program this?? gawk -vRS=";" -vORS=";\n" '1' infile > outfile e.g.: PS1> printf "a;b;c;" | gawk -vRS=";" -vORS=";\n" '1' a; b; c; You will have to deal with newlines or linefeeds if present in your input file and you don't want them in the output file. Ed.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.