transforming line content into columns
transforming line content into columns
am 15.02.2005 20:59:47 von Dieter Plass
Hello,
I have a set of files each containing one adress set with lines
FirstName: firstname1
LastName: lastname1
....
Email: email1
awk '/FirstName|LastName|Email/ { print $2 }' *
results in
firstname1
lastname1
email1
firstname2
lastname2
email2
....
However for import into a database I would like to get a textfile
firstname1 lastname1 email1
firstname2 lastname2 email2
....
Any suggestions would be appreciated - best if it were a simple one line
skript as my unix understanding doesnt't (yet) extend into that " if
when else ..." stuff!
Dieter
Re: transforming line content into columns
am 15.02.2005 22:43:06 von nospam
in a loop
use read to grab the variables,
for each line in the file, read the value to a variable,
then echo the result to an output file.
look for a scritpt example that reads a line into a variable and adapt it.
echo $first $last $email >> output.file
Re: transforming line content into columns
am 15.02.2005 22:44:01 von Ed Morton
Dieter Plass wrote:
> Hello,
>
> I have a set of files each containing one adress set with lines
>
> FirstName: firstname1
> LastName: lastname1
> ....
> Email: email1
>
> awk '/FirstName|LastName|Email/ { print $2 }' *
>
> results in
>
> firstname1
> lastname1
> email1
> firstname2
> lastname2
> email2
> ...
>
> However for import into a database I would like to get a textfile
>
> firstname1 lastname1 email1
> firstname2 lastname2 email2
Try this:
awk '/FirstName/{n=$2}/LastName/{n=n" "$2}/Email/{print n" "$2}/'
Regards,
Ed.
Re: transforming line content into columns
am 16.02.2005 03:04:05 von Icarus Sparry
On Tue, 15 Feb 2005 20:59:47 +0100, Dieter Plass wrote:
> Hello,
>
> I have a set of files each containing one adress set with lines
>
> FirstName: firstname1
> LastName: lastname1
> ....
> Email: email1
>
> awk '/FirstName|LastName|Email/ { print $2 }' *
>
> results in
>
> firstname1
> lastname1
> email1
> firstname2
> lastname2
> email2
> ...
>
> However for import into a database I would like to get a textfile
>
> firstname1 lastname1 email1
> firstname2 lastname2 email2
> ...
>
> Any suggestions would be appreciated - best if it were a simple one line
> skript as my unix understanding doesnt't (yet) extend into that " if
> when else ..." stuff!
If everyone has an email address
awk '/Firstname|LastName/ { printf "%s ", $2} /Email/ {print $2}' *
Re: transforming line content into columns
am 16.02.2005 05:24:41 von William Park
Dieter Plass wrote:
> Hello,
>
> I have a set of files each containing one adress set with lines
>
> FirstName: firstname1
> LastName: lastname1
> ....
> Email: email1
>
> awk '/FirstName|LastName|Email/ { print $2 }' *
>
> results in
>
> firstname1
> lastname1
> email1
> firstname2
> lastname2
> email2
> ...
If the order is guarenteed, then
awk '...' | paste -s -d ' \n'
>
> However for import into a database I would like to get a textfile
>
> firstname1 lastname1 email1
> firstname2 lastname2 email2
> ...
>
> Any suggestions would be appreciated - best if it were a simple one line
> skript as my unix understanding doesnt't (yet) extend into that " if
> when else ..." stuff!
--
William Park , Toronto, Canada
Slackware Linux -- because I can type.