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
How to replace a character in the file? ntgobinath Shell Programming and Scripting 2 06-04-2008 03:48 PM
How to replace many numbers with one number in a file vpandey AIX 2 02-27-2008 08:43 AM
How to replace a character in a file preethgideon Shell Programming and Scripting 6 08-30-2006 06:19 PM
How would you replace the n character in a file with some xyz? JosephGerard UNIX for Dummies Questions & Answers 2 07-21-2005 08:46 AM
How would I replace the 9th character of every line in a file? LordJezo Shell Programming and Scripting 5 09-01-2004 11:51 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-05-2007
cdfd123 cdfd123 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 112
Post to replace one character by numbers in a file

suppose u have a file

aas P-H 123
gdg O-U 223
hdy I-Y 12
fgd K-O 333
ssa L-P 32

output shud be like that
aas P123H
gdg O223U
hdy I12Y
fgd K333O
ssa L32P

thanks
  #2 (permalink)  
Old 10-05-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Code:
sed -n -e "s/\(.*\)-\([^ ]* \)\(.*\)/\1\3\2/p" input.txt

Last edited by vino; 10-05-2007 at 09:06 AM.. Reason: typo
  #3 (permalink)  
Old 10-05-2007
cdfd123 cdfd123 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 112
Quote:
Originally Posted by vino View Post
Code:
sed -n -e "s/\(.*\)-\([^ ]* \)\(.*\)/\1\3\2/g" input.txt
But if u have 0-9 digits then
\1\2\3 can we place [0-9]????
  #4 (permalink)  
Old 10-05-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,518
Code:
 # awk '{sub("-",$3,$2);$3=""}1' "file"
aas P123H
gdg O223U
hdy I12Y
fgd K333O
ssa L32P
  #5 (permalink)  
Old 10-05-2007
cdfd123 cdfd123 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 112
not working......

Quote:
Originally Posted by vino View Post
Code:
sed -n -e "s/\(.*\)-\([^ ]* \)\(.*\)/\1\3\2/g" input.txt
sorry not working......
Regards
  #6 (permalink)  
Old 10-05-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,518
Quote:
Originally Posted by cdfd123 View Post
sorry not working......
Regards
so are we expected to guess what's wrong? show your error messages..
  #7 (permalink)  
Old 10-05-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Quote:
Originally Posted by cdfd123 View Post
But if u have 0-9 digits then
\1\2\3 can we place [0-9]????
\1, \2, \3 so on and so forth are placeholders for the sub-regex expressions matched within each \( \) construct of a "s/regex/replacement/g" sed statement.

The sed statement should be
Code:
sed -n -e "s/\(.*\)-\([^ ]* \)\(.*\)/\1\3\2/p" input.txt
Sponsored Links
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 05:05 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