LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 01-02-2007, 05:19 PM   #1
resolute155
LQ Newbie
 
Registered: Dec 2006
Posts: 9

Rep: Reputation: 0
Linux Text Manipulation Question


Hello,

I have a file filled with the below. Below are the first two lines:

male_0103.bmp male_0314.bmp scene_0356.bmp scene_0517.bmp scene_0418.bmp
male_0016.bmp scene_0396.bmp male_0064.bmp scene_0568.bmp left.bmp
etc.

I want to put a comma after each portion of text. For example:

male_0103.bmp, male_0314.bmp, scene_0356.bmp, scene_0517.bmp, scene_0418.bmp,
male_0016.bmp, scene_0396.bmp, male_0064.bmp, scene_0568.bmp, left.bmp,


Is there a Linux command that would allow me to do this to the entire file? Maybe a command that would place a comma after each 'p'? (the only 'p' in the entire file is in .bmp).


Thanks!
 
Old 01-02-2007, 05:31 PM   #2
bitva
Member
 
Registered: Dec 2002
Location: Los Angeles
Distribution: Debian
Posts: 72

Rep: Reputation: 15
cat file | sed -e 's/p/p,/g'

where file is the filename. this is if bmp really is the only occurrence of p in the whole file.

Otherwise change it to 's/.bmp/.bmp,/g'
 
Old 01-02-2007, 05:48 PM   #3
jschiwal
Moderator
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,263

Rep: Reputation: 562Reputation: 562Reputation: 562Reputation: 562Reputation: 562Reputation: 562
A slight clarification. The decimal point is a single character wild card.

sed 's/\.bmp/.bmp,/g' file >newfile

You might want to add a sed command to undo the very last substitution on the last line:
sed -e 's/\.bmp/.bmp,/g' -e '/$/s/\.bmp,$/.bmp/' file >newfile

A line is read in one at a time, and every sed command is applied to that line. Each additional rule operates on the changed line.

Last edited by jschiwal; 01-02-2007 at 05:50 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
need help with text manipulation pcorajr Programming 12 12-15-2006 07:33 AM
text manipulation in scripts manicman Linux - Newbie 8 02-17-2006 05:04 AM
Manipulation of text files in C++ Hady Programming 5 05-31-2005 08:24 AM
More text manipulation ice_hockey Linux - General 2 05-28-2005 01:43 AM
CLI based Text manipulation selfsck Linux - General 1 07-15-2004 07:11 PM


All times are GMT -5. The time now is 08:52 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration