ulin
November 23, 2008, 1:53pm
1
hi all,
I use shell script to fetch some data's from my sybase database and i redirect my output to a file , i have some disorder in my file.my current o/p file looks like,
firstrecord|secondrecord|thirdrecord|fourthrecord|fivthrecord|s
ixhrecord|seventhrecord|
coulmnone|coulmntwo|coulmnthree|coulmnfour|coulmnfive|coul
mnsix|coulmnseven|
but my o/p needs to be in a single line
firstrecord|secondrecord|thirdrecord|fourthrecord|fivthrecord|sixhrecord|seventhrecord|
coulmnone|coulmntwo|coulmnthree|coulmnfour|coulmnfive|coulmnsix|coulmnseven|
am sure it is not query issue, Kindly adivice.Thanks in advance.
One way:
awk '!/\|$/ && NF{s=$0;getline;print s $0}' file
perl:
$/="\n\n";
open FH,"<content.txt";
@arr=<FH>;
map {s/\n//g} @arr;
print $_,"\n" foreach @arr;
awk:
awk '/^$/ { print "\n";next} {printf("%s",$0)}' filename
ulin
November 24, 2008, 7:50am
4
Hi
when i tried to use your cmd
awk '!/\|$/ && NF{s=$0;getline;print s $0}' Del.csv
am getting an error message as
awk: syntax error near line 1
awk: bailing out near line 1
Kindly advise.
ulin
November 24, 2008, 7:52am
5
Hi ,
Thanks for your post am doing my program in Shell script so am sticking on to it.
ulin:
Hi
when i tried to use your cmd
awk '!/\|$/ && NF{s=$0;getline;print s $0}' Del.csv
am getting an error message as
awk: syntax error near line 1
awk: bailing out near line 1
Kindly advise.
Use nawk, gawk or /usr/xpg4/bin/awk on Solaris.
Regards
ulin
November 25, 2008, 11:01am
7
hi ,
now am getting an output like below, kindly help
firstrecord|secondrecord|thirdrec
ord|fourthrecord|fivthrecord|s
ixhrecord|seventhrecord|
coulmnone|coulmntwo|coulmn
three|coulmnfour|coulmnfive|coul
mnsix|coulmnseven|
but my output needs to like
firstrecord|secondrecord|thirdrecord|fourthrecord|fivthrecord|sixhrecord|seventhrecord|
coulmnone|coulmntwo|coulmnthree|coulmnfour|coulmnfive|coulmnsix|coulmnseven|
regards
I get the desired output:
$ cat file
firstrecord|secondrecord|thirdrecord|fourthrecord|fivthrecord|s
ixhrecord|seventhrecord|
coulmnone|coulmntwo|coulmnthree|coulmnfour|coulmnfive|coul
mnsix|coulmnseven|
$ awk '!/\|$/ && NF{s=$0;getline;print s $0}' file
firstrecord|secondrecord|thirdrecord|fourthrecord|fivthrecord|sixhrecord|seventhrecord|
coulmnone|coulmntwo|coulmnthree|coulmnfour|coulmnfive|coulmnsix|coulmnseven|
$
Regards
ulin
November 26, 2008, 8:12am
9
Hi
i apologize for that, i have made a mistake in my query,my output looks like ,there is a whitespace in the continuation of the first line to the second line, but i need the output in a single line
firstrecord|secondrecord|thirdrecord|fourthrecord|fivthrecord|s
(Whitespace)ixhrecord|seventhrecord|
coulmnone|coulmntwo|coulmnthree|coulmnfour|coulmnfive|coul
(Whitespace)mnsix|coulmnseven|
which would need to be like ,
firstrecord|secondrecord|thirdrecord|fourthrecord|fivthrecord|sixhrecord|seventhrecord|
coulmnone|coulmntwo|coulmnthree|coulmnfour|coulmnfive|coulmnsix|coulmnseven|
Kindly advice.
ulin:
Hi
i apologize for that, i have made a mistake in my query,my output looks like ,there is a whitespace in the continuation of the first line to the second line, but i need the output in a single line
firstrecord|secondrecord|thirdrecord|fourthrecord|fivthrecord|s
(Whitespace)ixhrecord|seventhrecord|
coulmnone|coulmntwo|coulmnthree|coulmnfour|coulmnfive|coul
(Whitespace)mnsix|coulmnseven|
which would need to be like ,
firstrecord|secondrecord|thirdrecord|fourthrecord|fivthrecord|sixhrecord|seventhrecord|
coulmnone|coulmntwo|coulmnthree|coulmnfour|coulmnfive|coulmnsix|coulmnseven|
Kindly advice.
Try this:
awk '!/\|$/ && NF{s=$0;getline;sub(/^ /, "");print s $0}' file
ulin
December 3, 2008, 1:32am
11
Hi ,
Thanks you very much, the cmd worked fine for any file created with a tab in the second line. But as my file was generated through isql this cmd dint worked for me, as isql result has a default of 80 char, once i chaged the default column width it worked for me .
isql -w 250
this is the cmd used to set coulum width.
Thanks for your replies.