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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 10:24 AM
Too simple to search for spudtheimpaler UNIX for Dummies Questions & Answers 3 10-21-2006 12:55 PM
Search & replace videsh77 Shell Programming and Scripting 1 01-14-2005 07:10 AM
Simple Search and Replace - Revisited Brandt Shell Programming and Scripting 1 04-23-2004 10:45 AM
search and Replace mukeshannamalai UNIX for Advanced & Expert Users 4 09-14-2001 06:21 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 01-15-2004
Brandt Brandt is offline
Registered User
  
 

Join Date: Jan 2004
Posts: 8
Simple? Search replace

in vi, if i type ctrl-J, i can shift the next line up to the current line.
I need to do this whenever a specific string exists (in particular ^M) ,however i have not been able to find a way to do this in vi, sed, or awk

seems simple enough.

can someone help me?

thanks in advance
  #2 (permalink)  
Old 01-15-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,119
You must mean shift-J, not control J.

In vi you can do this:
:g/^M/j

But to type the ^M, you need to type cntl-V followed by cntl-M.
  #3 (permalink)  
Old 01-15-2004
Brandt Brandt is offline
Registered User
  
 

Join Date: Jan 2004
Posts: 8
thanks, but it does not join all of the ^Ms

240|^M\
^M\
^M\
Old Port Marketing order recd $62,664.- to ship 6/22/99^M\
^M\
^M\
^M\
^MCompleted by: C. Malczynski|


becomes:

240|^M\ ^M\
^M\ Old Port Marketing order recd $62,664.- to ship 6/22/99^M\
^M\ ^M\
^M\ ^MCompleted by: C. Malczynski|

but should be:

240|^M\ ^M\^M\ Old Port Marketing order recd $62,664.- to ship 6/22/99^M\^M\ ^M\^M\ ^MCompleted by: C. Malczynski|


this is what i typed :g/^M\\/j ----- (ctrl-V, ctrl-M)


any suggestions??

p.s. thanks, this has been stumping me for awhile

Last edited by Brandt; 01-15-2004 at 04:50 PM..
  #4 (permalink)  
Old 01-15-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,119
:g/^M\\$/j
and run the command a 2nd or third time until no more trailing ^M\ remain.
  #5 (permalink)  
Old 01-15-2004
Brandt Brandt is offline
Registered User
  
 

Join Date: Jan 2004
Posts: 8
thanks, this has been really helpful, but i need to run this on several files that have >1000000 records, which i can break down into smaller files if need be (migrating data in case you haven't guessed), hence the reason i was trying to find a one time fell swoop, the solution you provided is much better than me scrolling for ^M and hitting Shft-J five or six times, but also doesn't lend itself to being run unattended, do you know of a way to peform the same task with sed?

if not, the help you have given me has been great, and i appreciate your quick responses.

thanks again
  #6 (permalink)  
Old 01-15-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,119
This is a sed script. It does not use a shell. You must get all 11 lines exactly as I have them.
Code:
#! /usr/bin/sed -nf
#
#
s/^M\\$/^M\\/
H
t
x
s/\n//g
p
s/.*//
h
Call it combiner or something. Run it like:
combiner < oldfile > newfile
  #7 (permalink)  
Old 01-16-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
The paste command can be used for serial merging, e.g...
Code:
paste -s -d'' file1 > file2
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 04:13 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