LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 05-09-2009, 05:56 AM   #1
sunlinux
Member
 
Registered: Feb 2006
Distribution: RHCL 5
Posts: 239

Rep: Reputation: 30
text manipulation script


Hey programming brains,

I am lokin a script that can take a text file as input and add 0000 at the beginning of each line in that file.

it can be in any lang like shell script or c script
 
Old 05-09-2009, 06:02 AM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
You could use:
Code:
sed 's/^/0000 /' your_file
 
Old 05-10-2009, 11:59 PM   #3
sunlinux
Member
 
Registered: Feb 2006
Distribution: RHCL 5
Posts: 239

Original Poster
Rep: Reputation: 30
nice input , I checked and found only 1st line (beginning of file) is added with 0000 and nowhere else . It's windows text file I copied in linux seems vi editor considering all text file as 1 line.

is thr any method I can convert a text file as linewise(new line) after every 100 characters .
 
Old 05-11-2009, 12:14 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Windows files use a different kind of line break code from Unix ones. You'll have to convert it before most *nix tools will work properly. There are a multitude of ways to do this, including opening it up in one of the common text editors like kwrite or gedit and resaving it with the unix setting, or using a command-line application like flip.
 
Old 05-11-2009, 01:57 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
or use dos2unix
 
Old 05-11-2009, 03:24 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Then add a g for global in the sycamorex's solution:
Code:
sed 's/^/0000 /g' your_file
if you want to edit the file in place, use the -i option. -i.bck makes a backup copy of the original file adding the .bck extension (you can use any extension of your choice).
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
CSV | Text manipulation lmedland Programming 26 07-31-2008 10:44 AM
Easy string/text manipulation/indentation for restructured text brianmcgee Linux - Software 1 04-22-2008 08:27 PM
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
More text manipulation ice_hockey Linux - General 2 05-28-2005 01:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:04 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration