Read Embedded Newline characters with read (builtin) in KSH93
Hi Guys,
Happy New Year to you all!
I have a requirement to read an embedded new-line using KSH's read builtin.
Here is what I am trying to do:
I can take care of any embedded spaces by escaping them with a '\' in the run_sql utility and read would parse the value correctly.
However, address field can have embedded new line characters. Is there an escape sequence I can use to encode any embedded newlines, so the read command would store the new-line character in 'addr' variable?
I have tried '\n', but read doesn't recognize that escape-sequence.
Is there an option in read to accept embedded newlines? Or is there another builtin that can be used for this purpose?
Asking a line oriented tool to not be line oriented is tough, but if you know it is continued, say because of an escape character, why not read again and concatenate?
Asking a line oriented tool to not be line oriented is tough, but if you know it is continued, say because of an escape character, why not read again and concatenate?
I can write an abstraction layer (say, a function called readx) around read and use it instead of using read directly in my main loop.
However, I am writing a framework to integrate database access into the shell and want a minimum number of new functions/utilities to be introduced for my developers.
If there is a shell trick that can solve my problem then it would be great. Otherwise I will have to work around by creating custom function/builtin for the purpose.
read -r in ksh93 will leave the \n as they are. You can then use echo (or printf) to translate them to the correct character:
Hmm... this can be done. But it requires a step of post-processing the value after read, which I was trying to avoid.
Seems like extra processing will be required to solve my problem.
Suggest you write an sql program to output the fields to a file (not a pipe) in a more useable format. Maybe the whole process can be done in sql? Really depends what you are going to do with the data.
Well, how does the shell know which line feeds are real?
You might write a standard (local shared), postprocessing, sql tool (wrapper) for all to use, and make it encode embedded linefeeds in a printf friendly form, while escaping any printf metacharacters in the flow. It seems unlikely people will enter '\n' or '%' in their text, but with escapes, it would stay '\n' and '%'! It can trim and divert headers, counts, dividers and messages at the same time. It will be like JDBC/ODBC or ESQL, but crude and more work. Why not step up to a RDBMS tool or existing scripting extension for your RDBMS, sybperl or such?
Hello,
I have snippet code from Lippman's <<C++ primer>>.
The program is to convert regular decimal (0 ~ 15) numbers to basic hexdecimals. The instruction tells the program will execute by hitting newline at the end. When I tried to run the compiled program, hitting ENTER did not work as... (3 Replies)
Hi,
I want to read extended ASCII characters from keyboard using c language on unix/linux. How to read extended characters from keyboard or by copy-paste in terminal irrespective of locale set in the system. I want to read the input characters from keyboard, store it in an array or some local... (3 Replies)
Hi,
I have the file which has the data :
accctaaccctaaccctaaccctaaccctaaccctaaccctaaccctaac
cctaacccaaccctaaccctaaccctaaccctaaccctaaccctaacccc
taaccctaaccctaaccctaaccctaacctaaccctaaccctaaccctaa
ccctaaccctaaccctaaccctaaccctaacccctaaccctaaccctaaa... (24 Replies)
I have a txt like this:
638.301 (0.00973985) @ 50+55
the thing I want to do is read the last seven characters from the end of the first line.
how do I do this ?
Thanks in advance and sorry for being DOS only here. (2 Replies)
Hi,
I have file in which fields are pipe (|) separated and the record separator is new line (\n). But sometime I am getting a field value which is spread across multiple line. Basically I am getting a file from another system in the below format and needs to process the file and load data into a... (3 Replies)
Hi,
My program uses gl_get_line from libtecla to get user input from terminal. It works fine as long as I enter English at the terminal prompt. However, if I enter other languages, such as Chinese characters, either by typing in or cut-and-paste, the input characters get cleared from terminal... (5 Replies)
Hi ,
I am working on Linux, with ksh93 installed.
The following statement
echo \\n
just prints
\n on this shell.
However on pdksh
echo \\n gives a blank new line as a output.
What is the correct way of printing a new line character on the ksh93? (4 Replies)
I have a requirement where i have to read from a .sh file a text lying bet characters like 'SELECT' & ';'...Please help me out in this. I am new to shell scripting. (2 Replies)
Hey there - a bit of background on what I'm trying to accomplish, first off. I am trying to load the data from a pipe delimited file into a database. The loading tool that I use cannot handle embedded newline characters within a field, so I need to scrub them out.
Solutions that I have tried... (7 Replies)
Hi All
At the moment the following code works but ideally i do not want to have to change the original $1
tr "\r" "\n" < "$1" > "$1.fix"
printf "\n" >> "$1.fix"
mv "$1.fix" "$1"
FILE=$1
coffee_out="splitmovie"
coffee_fill="-splitAt"
coffee_end="-self-contained -o output.mov $2"... (1 Reply)