- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- conditional joining of lines
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2005 08:32 PM
10-30-2005 08:32 PM
conditional joining of lines
the following lines didnt work
awk '{if ($1 == NULL) {print X$0} else X=$0} END {print X}' tmp/search1.tmp > tmp/search111.tmp
sed 's/"\n "//g' tmp/search1.tmp > tmp/search111.tmp
this deletes evey \n and every space !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2005 09:18 PM
10-30-2005 09:18 PM
Re: conditional joining of lines
#----
{
head -1 toto
tail +2 toto | sed 's/^ /#TO_BE_JOIN# /' | awk '
{
if (NR == 1) LINE=$0
else
if ($1 == "#TO_BE_JOIN#") LINE=LINE $0
else { print LINE; LINE=$0 }
}
END { print LINE }
'
} | sed 's/#TO_BE_JOIN# //g'
#----
And my file 'toto' is :
hello
Line 2 no Join
Line 3 to be join with 1 remaining space
Line 4 to be join
end
The result is :
hello
Line 2 no Join Line 3 to be join with 1 remaining spaceLine 4 to be join
end
If file toto is :
hello
Line 2 no Join
Line 3 to be join with 1 remaining space
Line 4 to be join
end
then result is :
hello
Line 2 no Join Line 3 to be join with 1 remaining spaceLine 4 to be joinend
I think there is no side effect ...
Hope this will help
Eric
(PBFWME;-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2005 09:23 PM
10-30-2005 09:23 PM
Re: conditional joining of lines
i do not see in my previous answer some spaces i include in the code. In particulary
there a space folowing the tag '#TO_BE_JOIN#' in the sed commands
So here is an attachement where U will find the script as it shoul be
Regards
Eric
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2005 09:44 PM
10-30-2005 09:44 PM
Re: conditional joining of lines
#awk '{ if (match($0, /^ /)) {print X$0; X=NULL} else{ if(X != NULL)print X; X=$0}}'
#cat joinme.txt
aaaa
bbb
ccc
ddd
>>>eee
fff
ggg
hhh
>>>iii
where >>> designates a space
# awk '{ if (match($0, /^ /)) {print X$0; X=NULL} else{ if(X != NULL)print X; X=$0}}' joinme.txt
aaaa bbb
ccc
ddd eee
fff
ggg
hhh iii
hth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2005 12:24 AM
10-31-2005 12:24 AM
Re: conditional joining of lines
You could use this small perl script:
#!/usr/bin/perl
open( FH, "<", $ARGV[0] ) or die "Can't open $!\n";
$/ = undef;
$_ =
$_ =~ s%\n % %g;
print $_;
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2005 12:57 AM
10-31-2005 12:57 AM
Re: conditional joining of lines
'nother perl quicky:
perl -pe 'chomp; print "\n" unless /^ \S/' x.txt
The -p tells perl to loop through the input, put it in default var $_ and print $_ at then end of the block.
In the block we start by taking of the newline.
The newline is printed explicitly unless the line starts with a space.
An other perl way to express this, also taking care of the last line:
perl -pe 'chomp; print "\n" if (eof or /^[^ ]/)' x.txt
In awk you would need to call printf to avoid havinng print 'help' you with new-lines.
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2005 05:37 AM
10-31-2005 05:37 AM
Re: conditional joining of lines
cheers!