Batch Script to Trim lines in text to first 30 or 50 characters only
Posted
by
SuperUserMan
on Super User
See other posts from Super User
or by SuperUserMan
Published on 2014-08-18T11:38:09Z
Indexed on
2014/08/19
16:23 UTC
Read the original article
Hit count: 255
I am now new to scripts but i find it really difficult understanding "for" command (especially with that tokens and delimiters etc) . Saying so, i think that for command can be used to do what i am doing. If its not and there is an easier way, ignore my ignorance :(
Say i have multiple lines in a text file abc.txt with each line starting and ending with " (quotes) E.g. a file of 3 lines
"hey what is going on @mike220. I am working on your car. Its engine is in very bad condition"
"Because if you knew, you'd get shredded and do it with certainty"
"@honey220 Do you know someone who has busted their ass on a diet only for results to come to a screeching halt after a few weeks"
How can i trim each line, within the quotes, to a Fixed length say 30 or 50 or 100 characters (including spaces) I want to enter the number of character in batch and it can trim accordingly and produce a file def.txt with trimmed lines within quotes.
Say i enter 50, results of above example should be
"hey what is going on @mike220. I am working on you"
"Because if you knew, you'd get shredded and do it"
"@honey220 Do you know someone who has busted their"
Thanks
P.S. if you use For command, kindly please explain the command.
EDIT: Though the answer provided worked, there is an issue with non english text. I am getting garbled text in Output file for non english text in input file . Any help @barlop here is the nonenglish text ( 1 line)
"???? ?? ???? ?? ???? ???? ??? ?????? ???"
© Super User or respective owner