I need to make multiple string replacements in a file but several of the strings have been broken up by a carriage return so that the first few characters are on one line and the remainder on the following line.
E.g like the word 'post' in the following:
Use descriptive thread titles when posting. For example, do not po
st questions with subjects like "Help Me!", "Urgent!!" or "Doubt". Po
st subjects like "Execution Problems with Cron"
I'm using a korn shell script with embedded perl. Should run on both linux and solaris. I tried the following:
#rm all carriage returns
#replace the string
#add carriage returns every 80 characters
Seems to replace the string ok. However the format of the new output file is a bit messed up still when i try to put it back together again. Blank line are not handled for example. Not every line is cut to the correct length.
Any help greatly appreciated.
J
Last edited by Franklin52; 11-12-2013 at 09:35 AM..
Reason: Please use code tags
Blank lines are a sequence of two (or more) line feed chars. If you remove all of those, that info is lost.
Did you consider awk with its multi-line record feature?
I think perhaps my first step is not as it should be. If I use the following perl to merge a line with the one before it I get better formatting. It keeps the blank lines. However it does not keep lines that are less than 80 chars as they were. If I could get it to leave lines that are less than 80 chars alone it would mean only the code that needs to be changed is affected. So the last step of putting it back together would be simplified.
what do you think?
---------- Post updated 13-11-13 at 11:39 AM ---------- Previous update was 12-11-13 at 03:37 PM ----------
I thought I had the solution with the following but again the final file output contains lines longer than 79 characters. I'm operating on an ldif file so max line length and a space on the following line if it wraps around are essential.
# if a line begins with a space append it to previous line
# replace variable
# indent wrapped lines
# backup input file and split lines over 80 chars long
Alas the ouput file format is still not correct. Any help would be greatly appreciated. Thanks again.
Last edited by Franklin52; 11-13-2013 at 08:34 AM..
Reason: Please use code tags
I need to remove the carriage return comes inbetween the record.
Need to have CR only at the end.
I used the below command.
tr -d '\n' < filewithcarriagereturns > filewithoutcarriagereturns
But its removing all the CR and giving one line output.
Input File:
12345
abcdegh... (11 Replies)
Hello all,
I've a flat file in the following format:
AB\001\CDED\001\ABC\001\nEG\001\HIJF\001\EFG\001\nHI\003\HIUL\003\HIJ\003
And I want to substitute \n with the carriage return. Any help is appreciated!
Regards,
- Seth (8 Replies)
Hello,
How do i usecarriage return in ksh.
I want to do an echo "bla bla" and another echo "bla bla" will appear and replace the first echo on screen.
I tried:
until ; do
echo "bla bla \r"
done
please advice.
Thanks. (3 Replies)
Hi All,
I want to remove carriage return in a file using some unix command without writing a script
my file is as follows
abc1 abc2 abc3 abc4
abc5 bac6
abc1 abc2 abc3 abc4
abc5 bac6
I want the output as follows:
abc1 abc2 abc3 abc4 abc5 bac6
abc1 abc2 abc3 abc4 abc5 bac6
,
Please... (7 Replies)
Hey folks,
I've been working on this for some time. Seems simple, but I'm stumped.
I need the following data format:
New_York:Commercial
Geology
Geophysics
Petrophysics
Production_Engineering
Reservoir_Engineering
Pasadena:Commercial
... (5 Replies)
Hello, I want remove ^M at end of my files line
if I use command : tr -d '\r' <inp>out it work fine
but get I the same result by manipulating the string ?
I want this because in my text file I manipulate some other part
I have input "the cat^M"
I want output "the cat"
I have made... (3 Replies)
Hy everybody
I'm trying to write a function like
function(){
final=$1
return $final
}
but I get following error:
"return: bad non-numeric arg ''"
what shall I do? Isn't it possible to return strings?:confused:
thanks
lucae (2 Replies)
hi there
I'm getting a string from a sqlplus query, and I need to compare it with another string
Problem here, is that the string i get from query brings a 'carriage return' with it, and comparing throws always false value.
i need to delete all carriage retun charactres in string.
how... (6 Replies)
I have observed with print & echo, they produce carriage return <CR> or newline, after they display string next to them.
Is there anyway to avoide these <CR> after the intended string is displayed? (3 Replies)
I try to test the carriage return in a variable.
$ LENGTH=`expr $VARIABLE : ".*"` will return the length of the variable. But this doesn't work if $VARIABLE has zero length.
Any help will be well appreciated.
Thanks in advance.
Giovanni (4 Replies)