Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Line break trouble
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

Report this thread to moderator Post Follow-up to this message
Old Post
BlackSun
12-03-04 08:56 PM


Re: Line break trouble
BlackSun 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

Report this thread to moderator Post Follow-up to this message
Old Post
Koriolan
12-03-04 08:56 PM


Re: Line break trouble

BlackSun 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.

Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
12-03-04 08:56 PM


Re: Line break trouble
BEGIN { FS=";"
OFS=";\n"
ORS=""
}
{ $1=$1; print }

Report this thread to moderator Post Follow-up to this message
Old Post
William James
12-04-04 01:55 AM


Re: Line break trouble

BlackSun 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.

Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
12-07-04 08:59 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:19 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.