English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have a text file where files are listed as so:
Lesson 3: Interactive Learning
Lesson 4: Stories About Separating VLB
Lesson 5: Interactive Learning
Lesson 6: Close/Assess
Lesson 7: Differentiated Instruction

and so on for 20 chapters, 1139 lines in all.

I need to make the text simply say Lesson X where X is the number.

Essentially, I need to delete anything after the colon.

Is there any program or any way to do this?

2007-02-19 08:44:45 · 5 answers · asked by Wes Ide 2 in Computers & Internet Programming & Design

5 answers

Use a text editor which supports "regular expressions" (I use TextPad).

Find (without quotes) ":.*$" and replace with "".

Good luck!

2007-02-19 08:54:38 · answer #1 · answered by Anonymous · 0 0

Yes, that can be done via a script. You will have to open a text file, read the file line by line, if a line starts with "lesson", find ":" character and remove everything after. You will have to write everything in a temp file (including unmodified lines). At the end you delete original file (or rename) and rename the temp file with the original file name.

I will not publish the script here but you will find numerous examples on the Internet if you search a little.

Good luck.

2007-02-19 08:51:09 · answer #2 · answered by Milu 4 · 0 0

you'd have to write the program yourself.

You just need to read a line at a time and if it matches the prefix lesson x: then truncate the line

at each step just write the line back to the file.

2007-02-19 08:48:11 · answer #3 · answered by irishtek 6 · 0 0

If it is a plain text document then yes.

Here are a couple batch script you could use:

SCRIPT1.CMD
for /f "delims=&" %%x in (nameoffile.txt) do SCRIPT2.CMD %%x

SCRIPT2.CMD
echo %1 | find "Lesson" | find ":"
if %errorlevel% equ 0 goto chopline
echo %1 >> outputfile.txt
goto end

:choplne
set value=%1
set line=
:loop
set test=%value:~0,1%
if %test% == : goto endloop
set line=%line%%test%
set value=%value:~1%
goto loop
:endloop
echo %line% >> outputfile.txt
:end

2007-02-19 08:48:23 · answer #4 · answered by Amanda H 6 · 0 0

sed -e "s/[Ll]esson [0-9]/Lesson X/" < infile | cut -f":" -d1 > outfile

2007-02-19 08:53:07 · answer #5 · answered by Vegan 7 · 0 0

fedest.com, questions and answers