Hello guys,
I have a little problem, i already have a txt file like:
-------------------
1
2
3
-------------------
2
3
4
5
-------------------
2
3
4
I need a script to merge in a single line al the lines between the '-------------------' line and to get a new file like:
1|2|3
2|3|4|5
2|3|4
Thanx for your help.
nawk '$1=$1' RS='-' OFS='|' myFile
Thanx vgersh99 but my lines are words like:
-----------------
I am
You are
he is
-----------------
she is
it is
-----------------
And your script insert '|' in each space between words, i need an output like:
I am|you are|he is
she is|it is
please your help.
a lil' UUOC-ish, but..... - have to think about it.......
sed 's/^-*$//g' myFile | nawk '$1=$1' RS="" FS="" OFS="|"
awk '
/^--*$/ && NR > 1 { print ""}
/^--*$/ { print; next }
{ $1=$1; printf "%s|", $0 }'
perl:
$/="-----------------\n";
while(<DATA>){
s/\n/|/g;
s/[|]?-+[|]?//;
print $_,"\n" if $_;
}
__DATA__
-----------------
I am
You are
he is
-----------------
she is
it is
-----------------