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
Replacing Comma by Tab Serious Sam UNIX for Dummies Questions & Answers 9 01-16-2009 05:21 PM
vi or vim replace ,$ (eol) with just a comma dbauhaus UNIX and Linux Applications 6 10-02-2008 09:02 AM
Split by comma mahalakshmi Shell Programming and Scripting 2 12-18-2006 08:16 AM
Comma seperator premar Shell Programming and Scripting 6 02-17-2006 04:16 AM
Add a comma at end of every line ST2000 Shell Programming and Scripting 4 07-14-2002 06:49 PM

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-18-2002
alisevA3 alisevA3 is offline
Registered User
  
 

Join Date: May 2002
Posts: 33
Lightbulb add comma

I have a file like this

101223345
23232344a
1312a3441
903821224
143434324
101223345
23232344a
1312a3441

I want to insert comma in 5 digit.
it should be like
10122,3345
23232,344a

how can I do this ?

thanks
Alice...
  #2 (permalink)  
Old 10-18-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
sed 's/\(^.....\)/\1,/' < input > output
  #3 (permalink)  
Old 10-18-2002
Vishnu Vishnu is offline
Registered User
  
 

Join Date: Aug 2002
Location: Marlboro, MA
Posts: 114
try this...

for i in `cat yourfile`
do
col1=`echo $i | cut -b1-5`
col2=`echo $i | cut -b6-`
echo $col1 ',' $col2
done

there will be more straight forward way than this... and I will love to see that...

  #4 (permalink)  
Old 10-18-2002
Vishnu Vishnu is offline
Registered User
  
 

Join Date: Aug 2002
Location: Marlboro, MA
Posts: 114
I got the answer I wanted!

correct me if I'm wrong... here Perderabo used sed with a tagged regular expression

\(^.....\) -- this will tag the first 5 characters in the input string

\1, -- \1 refers the above tagged 5 characters and just put a , after that...

this is elegant...
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 11:10 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