The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
any better way to remove line breaks csmklee Shell Programming and Scripting 3 01-13-2009 02:42 AM
'exec /bin/sh' breaks alias stulincoln Shell Programming and Scripting 1 05-29-2008 12:00 PM
Help on page breaks simhasuri Shell Programming and Scripting 1 01-31-2008 04:51 PM
Newbie ? Need Help with If/Then & Line Breaks... kthatch UNIX for Dummies Questions & Answers 1 05-01-2007 07:44 PM
Page Breaks rama71 High Level Programming 9 06-29-2005 12:28 PM

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

Join Date: Dec 2008
Posts: 10
Fix the breaks

The file FTP'd got few breaks and the data looks like:

ABCTOM NYMANAGER
ABCDAVE NJ
PROGRAMMER
ABCJIM CTTECHLEAD
ABCPETERCA
HR


and i want the output like:

ABCTOM NYMANAGER
ABCDAVE NJPROGRAMMER
ABCJIM CTTECHLEAD
ABCPETERCAHR


can you please help me in writing the shell script to fix these broken lines.
Every line is supposed to start with 'ABC' (key positions). Also the break is always at the 11th position and continues on the next line at 4th position..

Thanks
  #2 (permalink)  
Old 12-31-2008
rubin's Avatar
rubin rubin is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2007
Posts: 321
Code:
$ cat file
ABCTOM NYMANAGER
ABCDAVE NJ
PROGRAMMER
ABCJIM CTTECHLEAD
ABCPETERCA
HR

Code:
awk '{ printf (NR==1) ? $0 : /^ABC/ ? RS $0 : $0 } END{ print eof }'  file

Output:

Code:
ABCTOM NYMANAGER
ABCDAVE NJPROGRAMMER
ABCJIM CTTECHLEAD
ABCPETERCAHR
  #3 (permalink)  
Old 12-31-2008
Christoph Spohr Christoph Spohr is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 205
Or in good old sed:

command:
Code:
sed ':a;$!N;/\nABC/!s/\n//;ta;P;D' file
input:
Code:
ABCTOM NYMANAGER
ABCDAVE NJ
PROGRAMMER
ABCJIM CTTECHLEAD
ABCPETERCA
HR
output:
Code:
ABCTOM NYMANAGER
ABCDAVE NJPROGRAMMER
ABCJIM CTTECHLEAD
ABCPETERCAHR
  #4 (permalink)  
Old 12-31-2008
rlmadhav rlmadhav is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 10
low & high values

on the file Ftp'd from the mainframe ,do we have any UNIX command to replace mainframe low and values to space or null.

i tried using tr and it doesn't work ...

Thanks
  #5 (permalink)  
Old 12-31-2008
rlmadhav rlmadhav is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 10
i am getting the following errors!!.. Please advise


awk '{printf (NR==1)?$0:/^'ABC'/?RS$0:$0}END{print eof}' file
awk: syntax error near line 1
awk: illegal statement near line 1



sed ':a;$!N;/\nABC/!s/\n//;ta;P;D' file

Label too long: :a;$!N;/\nABC/!s/\n//;ta;P;D
  #6 (permalink)  
Old 12-31-2008
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,209
With a classical sed, you would have to expand that to:

Code:
sed -e ':a' -e '$!N' -e '/\nABC/!s/\n//' -e 'ta' -e 'P;D'
or with a classical awk something like this:
Code:
awk 'NR>1 && /^ABC/ {printf "\n%s", $0 ; next } { printf "%s", $0  } END {print eof}'
  #7 (permalink)  
Old 01-03-2009
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,209
Code:
sed -e ':a' -e '$!N' -e '/\nABC/!s/\n //' -e 'ta' -e 'P;D'

Code:
awk 'NR>1 && /^ABC/ {printf "\n%s", $0 ; next } { printf " %s", $0  } END {print eof}'
Closed Thread

Bookmarks

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 10:15 PM.


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