[opensuse] Another grep question
Hi all,, I'm not sure if this is a grep or awk question. I have a file with many records of 4 lines each in it. Like this: 1 2 3 4 1 2 3 4 etc, etc I need the file to look like this: 1 tab 2 tab 3 tab 4 1 tab 2 tab 3 tab 4 etc etc.... How can I do this? Thanks, JIM -- Jim Hatridge Linux User #88484 Ebay ID: WartHogBulletin ------------------------------------------------------ WartHog Bulletin Info about new German Stamps http://www.WartHogBulletin.de Many Enemies -- Much Honor! Anti-US Propaganda stamp collection http://www.manyenemies-muchhonor.info An American in Bavaria http://www.gaubodengalerie.de -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Sun, 2007-04-08 at 20:49 +0200, James Hatridge wrote:
I'm not sure if this is a grep or awk question. I have a file with many records of 4 lines each in it. Like this:
1 2 3 4 1 2 3 4 etc, etc
I need the file to look like this:
1 tab 2 tab 3 tab 4 1 tab 2 tab 3 tab 4 etc etc....
I imagine sed is your friend. Replace the newline character with the tab character. Don't ask me the syntax though. Of course, that doesn't take care of the groups for three though... Hans -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Sunday 08 April 2007 20:49:02 James Hatridge wrote:
Hi all,,
I'm not sure if this is a grep or awk question. I have a file with many records of 4 lines each in it. Like this:
1 2 3 4 1 2 3 4 etc, etc
I need the file to look like this:
1 tab 2 tab 3 tab 4 1 tab 2 tab 3 tab 4 etc etc....
How can I do this?
Perhaps with bash? #!/bin/bash while read line1; do read line2; read line3; read line4; echo -e "$line1\t$line2\t$line3\t$line4" >> outputfile done < testfile -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Jim:
How about a Perl solution?
I'm sure a Perl Guru could do it in one line but it works on a file
created on a Linux box.
If the original data was created on a Windoze box you may need to deal
with other end of line issues. Also, if there are stray spaces laying
around that may cause grief -
Hope it works!
No warranty - implicit or implied!
Michael
concat4lines.pl
=================================
#!/usr/bin/perl -w
#
# Author: Michael W Folsom
#
# April 8, 2007
#
# USAGE: ./concat4lines.pl input_file_name
#
#
open(FILE, $ARGV[0]);
$NewStr ="";
$i = 0;
while (<FILE>) {
# assign the contents of the current line in the file
# to the built in variable $_
chomp($_);
if($i < 4) {
#print $_;
$NewStr = $NewStr . $_;
$i++;
if($i < 4) {
#print "\t";
$NewStr = $NewStr . "\t";
}
else {
print "$NewStr \n";
#$NewStr = $NewStr . "\n";
$i= 0;
$NewStr = "";
}
}
}
# if number of lines not equal to 4 then print out left overs
if($NewStr) {
print "$NewStr\n";
}
close(FILE);
exit();
=====================================================
On 4/8/07, James Hatridge
Hi all,,
I'm not sure if this is a grep or awk question. I have a file with many records of 4 lines each in it. Like this:
1 2 3 4 1 2 3 4 etc, etc
I need the file to look like this:
1 tab 2 tab 3 tab 4 1 tab 2 tab 3 tab 4 etc etc....
How can I do this?
Thanks,
JIM -- Jim Hatridge Linux User #88484 Ebay ID: WartHogBulletin ------------------------------------------------------ WartHog Bulletin Info about new German Stamps http://www.WartHogBulletin.de
Many Enemies -- Much Honor! Anti-US Propaganda stamp collection http://www.manyenemies-muchhonor.info
An American in Bavaria http://www.gaubodengalerie.de -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
James Hatridge wrote:
I'm not sure if this is a grep or awk question. I have a file with many records of 4 lines each in it. Like this:
1 2 3 4 1 2 3 4 etc, etc
I need the file to look like this:
1 tab 2 tab 3 tab 4 1 tab 2 tab 3 tab 4 etc etc....
How can I do this?
$> paste - - - - < file.in > file.out Th. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Hi Thomas et al.. This was what I was looking for. Thanks, JIM On Monday 09 April 2007 00:59, Thomas Hertweck wrote:
James Hatridge wrote:
I'm not sure if this is a grep or awk question. I have a file with many records of 4 lines each in it. Like this:
1 2 3 4 1 2 3 4 etc, etc
I need the file to look like this:
1 tab 2 tab 3 tab 4 1 tab 2 tab 3 tab 4 etc etc....
How can I do this?
$> paste - - - - < file.in > file.out
Th.
-- Jim Hatridge Linux User #88484 Ebay ID: WartHogBulletin ------------------------------------------------------ WartHog Bulletin Info about new German Stamps http://www.WartHogBulletin.de Many Enemies -- Much Honor! Anti-US Propaganda stamp collection http://www.manyenemies-muchhonor.info An American in Bavaria http://www.gaubodengalerie.de -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (5)
-
Anders Johansson
-
Hans du Plooy
-
James Hatridge
-
Michael Folsom
-
Thomas Hertweck