The UNIX and Linux Forums  


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
Removing last character from each line of file cjhancock Shell Programming and Scripting 17 08-29-2008 05:05 AM
Need to serach if a new line character exists on the last line in a file sunilbm78 UNIX for Dummies Questions & Answers 10 02-29-2008 02:15 PM
removing new line character ammu Shell Programming and Scripting 2 01-15-2008 10:12 AM
Removing character from list line (at the end) malaymaru Shell Programming and Scripting 2 11-28-2007 08:05 AM
Removing a particular line from a text file sendhilmani123 Shell Programming and Scripting 5 05-31-2006 09:32 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-28-2008
arunkumar_mca arunkumar_mca is offline
Registered User
  
 

Join Date: Oct 2004
Posts: 256
removing a character and addending to end in each line in a file

HI i am having a file this

(sys19nlfct:/pfact/temp>) cat temp_sand
1234567890
1234567890
1234567890
1234567890


I want to make this file as
(sys19nlfct:/pfact/temp>) cat temp_sand
1456789023
1456789023
1456789023
1456789023


just take the 2nd and 3rd position and put it in end of ecah line . PLease let me know how to do that

Thanks,
Arun
  #2 (permalink)  
Old 01-28-2008
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,128
echo '1234567890' | sed 's/^\(.\)\(..\)\(.*\)/\1\3\2/'
-->
Code:
echo '1234567890' | sed 's/^\(.\)\(..\)\(.*\)/\1\3\2/'
        

Last edited by vgersh99; 01-28-2008 at 12:58 PM.. Reason: 2nd and 3rd (not 3rd and 4th)
  #3 (permalink)  
Old 01-28-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 753
sed 's/^\([0-9]\)\([0-9]\{2\}\)\([0-9]*\)$/\1\3\2/' file
-->
Code:
sed 's/^\([0-9]\)\([0-9]\{2\}\)\([0-9]*\)$/\1\3\2/' file
        
  #4 (permalink)  
Old 01-29-2008
arunkumar_mca arunkumar_mca is offline
Registered User
  
 

Join Date: Oct 2004
Posts: 256
Thanks all,

can you please let me know how it is done there . I have done the same by replacing the number it is not working.

echo '1234567890' | sed 's/^\(..\)\(..\)\(.*\)/\1\3\2/'

it is working but the same below is not working

echo '1234567890' | sed 's/^\(..\)\(..\)\(.*\)/\1\3\3/'

why it is not working ??.

Thanks in advance ,
Arunkumar
  #5 (permalink)  
Old 01-29-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,934
It is giving you the right result albeit it may not be the result you want

$ echo '1234567890' | sed 's/^\(..\)\(..\)\(.*\)/\1\3\3/' 12567890567890
-->
Code:
$ echo '1234567890' | sed 's/^\(..\)\(..\)\(.*\)/\1\3\3/'
12567890567890
        
The first pattern, i.e. \1, is "12"
The second pattern, i.e. \2, is "34"
The third pattern, i.e. \3, is "567890"
  #6 (permalink)  
Old 01-30-2008
arunkumar_mca arunkumar_mca is offline
Registered User
  
 

Join Date: Oct 2004
Posts: 256
thanks ... I got into my head how it works
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 07:25 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