LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   text manipulation script (https://www.linuxquestions.org/questions/programming-9/text-manipulation-script-724839/)

sunlinux 05-09-2009 05:56 AM

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

sycamorex 05-09-2009 06:02 AM

You could use:
Code:

sed 's/^/0000 /' your_file

sunlinux 05-10-2009 11:59 PM

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 .

David the H. 05-11-2009 12:14 AM

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.

chrism01 05-11-2009 01:57 AM

or use dos2unix

colucix 05-11-2009 03:24 AM

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).


All times are GMT -5. The time now is 04:23 AM.