The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Conditional merging of lines sunny23 Shell Programming and Scripting 4 09-06-2008 12:31 PM
concat strings melanie_pfefer Shell Programming and Scripting 1 12-04-2007 07:12 AM
concat string mpang_ Shell Programming and Scripting 1 07-25-2006 07:03 AM
Concat dhananjaysk Shell Programming and Scripting 1 03-20-2006 07:42 AM
Concat date drukkie UNIX for Dummies Questions & Answers 2 05-30-2002 08:36 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-15-2008
carloskl carloskl is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 3
Conditional concat lines awk

Hello,
I have a text file like this:
NONE FILE_Rename
frompath: /log_audit/AIX/log/current/AIXAFTPP.log
NONE FILE_Unlink
filename /audit/tempfile.14041142
NONE FILE_Rename
NONE FILE_Rename
filename /log_audit/AIX/log/last/S372008.log
I would like to obtain a output text file using awk script:
1) If i have two lines like this i would like to concatenate in one.
NONE FILE_Rename
frompath: /log_audit/AIX/log/current/AIXAFTPP.log
2) If i have two lines like this i don't want to concatenate.
NONE FILE_Rename
NONE FILE_Rename

Thanks a lot.
  #2 (permalink)  
Old 10-15-2008
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,918
Try:

Code:
awk 'END{print RS}$0=(/^NONE/?NR==1?_:RS:FS)$0' ORS= file

If you get no output, try this:


Code:
awk 'END{print RS}$0=(/^NONE/?NR==1?_:RS:FS)$0;1' ORS= file

  #3 (permalink)  
Old 10-15-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,338
Or just something like this?


Code:
awk '/^NONE FILE/{s=$0;next}{print s " "$0}' file

Regards
  #4 (permalink)  
Old 10-15-2008
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,918

Code:
% cat file
NONE FILE_Rename
frompath: /log_audit/AIX/log/current/AIXAFTPP.log
NONE FILE_Unlink
filename /audit/tempfile.14041142
NONE FILE_Rename
NONE FILE_Rename
filename /log_audit/AIX/log/last/S372008.log


% awk '/^NONE FILE/{s=$0;next}{print s " "$0}' file        
NONE FILE_Rename frompath: /log_audit/AIX/log/current/AIXAFTPP.log
NONE FILE_Unlink filename /audit/tempfile.14041142
NONE FILE_Rename filename /log_audit/AIX/log/last/S372008.log


% awk 'END{print RS}$0=(/^NONE/?NR==1?_:RS:FS)$0' ORS= file
NONE FILE_Rename frompath: /log_audit/AIX/log/current/AIXAFTPP.log
NONE FILE_Unlink filename /audit/tempfile.14041142
NONE FILE_Rename
NONE FILE_Rename filename /log_audit/AIX/log/last/S372008.log

  #5 (permalink)  
Old 10-15-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,338
Quote:
Originally Posted by radoulov View Post
Code:
% awk 'END{print RS}$0=(/^NONE/?NR==1?_:RS:FS)$0' ORS= file
NONE FILE_Rename frompath: /log_audit/AIX/log/current/AIXAFTPP.log
NONE FILE_Unlink filename /audit/tempfile.14041142
NONE FILE_Rename
NONE FILE_Rename filename /log_audit/AIX/log/last/S372008.log
Yes, I know, but it's not really clear to me what the OP expect.

Regards
  #6 (permalink)  
Old 10-15-2008
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,918
Quote:
Originally Posted by Franklin52 View Post
Yes, I know, but it's not really clear to me what the OP expect.

Regards
Waiting for the OP to clarify ...

Perl addition: if the file is not too big


Code:
perl -p0e's/\n(?!(^NONE|\Z))/ /mg' file


Last edited by radoulov; 10-15-2008 at 07:23 AM..
  #7 (permalink)  
Old 10-15-2008
carloskl carloskl is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 3
sorry is not running

Also at the begin of the file i have a head text like:

host event login real process parent st
---------------- --------------- -------- -------- -------- --

I need to call the script like: script inputfile outputfile
Thanks
Closed Thread

Bookmarks

Tags
concat lines awk conditional file

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:55 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0