- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- join two line is a file
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
03-14-2004 09:40 AM
03-14-2004 09:40 AM
How it stands is I have a block of data 2 rows then a space, the first row ends with 5 digits and a ^M, I need to search for this and join it with the second line.
I want this...
2004/01/02 12:18:23 Access granted 05007
DO007 M-Turnstile (Left) 4D:60065 XXXXXX, ROBERT
With this...
2004/01/02 12:18:23 Access granted 05007 DO007 M-Turnstile (Left) 4D:60065 XXXXXX, ROBERT
How would I do that?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2004 09:58 AM
03-14-2004 09:58 AM
Re: join two line is a file
/01/02 12:18:23 Access granted 05007
DO007 M-Turnstile (Left) 4D:60065 XXXXXX, ROBERT
/01/02 12:18:23 Access granted 05007
DO007 M-Turnstile (Left) 4D:60065 XXXXXX, ROBERT
/01/02 12:18:23 Access granted 05007
DO007 M-Turnstile (Left) 4D:60065 XXXXXX, ROBERT
I just copied paste but the data would be different in each group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2004 11:04 AM
03-14-2004 11:04 AM
SolutionOne of many solutions:
perl -p -e 'if (/\s\d{5}.$/) { chop; chop; $_ .= " ". <> }' < x
This looks explicitly for white-space, 5 decimals, random-character, end-of-line.
You could not chop but 'catch' the begin
perl -p -e 'if (/(^.*\s\d{5}).$/) { $_ = $1." ". <> }' < x
Or in awk:
awk '/ [0-9]+.$/{x=substr($0,1,length - 1); getline; print x,$0}' < x
Enjoy,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2004 07:19 PM
03-14-2004 07:19 PM
Re: join two line is a file
> perl -p -e 'if (/\s\d{5}.$/) { chop; chop; $_ .= " ". <> }' < x
perl -pe 'if (/\s\d{5}.$/) {chop;chop}' < x
does the same, as does
perl -pe's/(\s\d{5})..\z)/$1/s'
but sorter and faster
because -p is nothing but an internal wrapper for
while (<>) {
... your -e code here ...
} continue { print }
so in hein's example he does not have to catenate the current line withh the next line, because both are printed anyway
> You could not chop but 'catch' the begin
>
> perl -p -e 'if (/(^.*\s\d{5}).$/) { $_ = $1." ". <> }' < x
perl -pe'/(^.*\s\d{5}).$/ and $_="$1 "' < x
in the same line of thought
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2005 01:19 AM
02-23-2005 01:19 AM