I'm trying to fully escape/quote a directory path for use in a regular expression with no characters interpreted symbolically. Printable characters get \* and white space gets "*"
Is in a new line but why? ---------- Post updated at 06:59 PM ---------- Previous update was at 06:54 PM ----------
Well, this works fine but here strings seem quirky.
Mike
I don't think they're quirky. bash expands the here string's variable into a temp text file and redirects stdin (FD 0 below) thereto:
Any text file is terminated by a <NL> char, which is read into your "a" variable as well and treated/printed out (maybe converted to a NULL char by the shell)
I don't think they're quirky. bash expands the here string's variable into a temp text file and redirects stdin (FD 0 below) thereto:
Any text file is terminated by a <NL> char, which is read into your "a" variable as well and treated/printed out (maybe converted to a NULL char by the shell)
The read built-in always strips the trailing <newline> character from lines it reads.
If read didn't work this way, the common sequence:
(a dangerous way to implement cat file as a shell script) would double-space all of its output.
Similarly command substitution (both `commnd` and $(command)) strips trailing <newline> characters if one or more are present. Try, for example:
which produces the output:
Then, please help me understand this (built on Michael's sample code):
To me it looks like the file is read char by char, and the <NL>s are replaced by NULL chars.
The read -n num_chars option is an extension to the standards that overrides the default behavior. Try that again without the -n1, and print using strings and you'll get what I suggested:
producing:
(I used od -c instead of hd because hd isn't available on my system.)
When invoked as:
the current standards describe the requirements as:
Quote:
The terminating <newline> (if any) shall be removed from the input and the results shall be split into fields as in the shell for the results of parameter expansion (see Section 2.6.5, on page 2333); the first field shall be assigned to the first variable var, the second field to the second variable var, and so on. If there are fewer fields than there are var operands, the remaining vars shall be set to empty strings. If there are fewer vars than fields, the last var shall be set to a value comprising the following elements:
The field that corresponds to the last var in the normal assignment sequence described above
The delimiter(s) that follow the field corresponding to the last var
The remaining fields and their delimiters, with trailing IFS white space ignored
Yes, I thought the same and attributed above behaviour to the -n x option.
So, this non-standard behaviour would explain Michael's findings in his first post of this thread, wouldn't it?
Hi Rudi,
Michael Stora hasn't explained what he means by "quirky". The command and corresponding output shown in his first message in this thread:
ends with a <newline> character because the echo shown in red above adds a <newline> to the output from the command substitution. I see nothing surprising in that. Did I miss some deeper point? I certainly see no evidence that read stored a newline character in a at any time.
I guess I didn't pay much attention to this thread before because all of the echo commands in this thread are non-portable and Michael didn't even bother to tell us what OS or shell he's using. Looking at it closer now, I can deduce that his version of echo uses -n to eliminate the trailing <newline> normally produced as output and that it doesn't expand \ escapes in the strings being processed. But with no explanation of what "quirky" means I didn't see anything that would lead me to guess at what he was expecting that he didn't get.
As I have said in MANY MANY other threads, I always (except when responding to threads like this) avoid echo whenever the 1st argument can have a minus sign as the 1st character (even if the 1st argument is --) and whenever any argument can contain a backslash character. Using printf instead of echo requires two more keystrokes plus a format string, but you always know what you'll get.
My file (the output of an experiment) starts off looking like this,
_____________________________________________________________
Subjects incorporated to date: 001
Data file started on machine PKSHS260-05CP
**********************************************************************
Subject 1,... (9 Replies)
Hi,
I have a file which is an extract of jil codes of all autosys jobs in our server.
Sample jil code:
**************************
permission:gx,wx
date_conditions:yes
days_of_week:all
start_times:"05:00"
condition: notrunning(appDev#box#ProductLoad)... (1 Reply)
Hi
I have a very large data file with several hundred columns and millions of lines.
The important data is in the last set of columns with variable numbers of tab delimited fields in front of it on each line.
Im currently trying sed to get the data out - I want anything beetween :RES and... (4 Replies)
Platform: Solaris 10
I have a file like below
$ cat languages.txt
Spanish
Norwegian
English
Persian
German
Portugese
Chinese
Korean
Hindi
Malayalam
Bengali
Italian
Greek
Arabic
I want to append the string " is a great language" at end of each line in this file. (3 Replies)
Dear All
I am having a text file which is having more than 200 lines.
EX:
001010122 12000 BIB 12000 11200 1200003
001010122 2000 AND 12000 11200 1200003
001010122 12000 KVB 12000 11200 1200003
In the above file i want to search for string KVB... (5 Replies)
I've a problem to put .h end of the line..below my input file
fg_a
bb
fg_b
bb
fg_c
bb
fg_d
aa
fg_f
ee
and i want the output file as below
fg_a.h
bb
fg_b.h
bb
fg_c.h
bb
fg_d.h (6 Replies)
Hello
How can I add a string (always the same) at the end of a specific line in a file...
The file is:
000000001 041 L $$aspa
000000001 088 L $$aJ.E.N. 551
000000001 090 L $$aINFORMES JEN
000000001 100 L $$aautor 1
----
000000002 041 L $$aeng
000000002 088 L $$aJ.E.N. 1... (13 Replies)
Hi, guys. I have one question:
I have a file called "group", the contents of it is below:
********************************
...
test:x:203:
sales:x:204:
repair:x:205:
research:x:206:brownj
...
***********
Now I want to add string ",sherrys" at the end of "research:x:206:brownj", so... (5 Replies)
I have a comma delimited text file and need to appened ",000000" to the end of every line. For example:
Before:
"D700000","2006" ,"5000","Open Year" ,"Conversion" ,"Wk64","Productive Payroll $" ,1103.45
After:
"D700000","2006" ,"5000","Open Year" ,"Conversion" ,"Wk64","Productive Payroll... (3 Replies)
HI,
I want to cut end string from line.
e.g. i have following input line
/users/home/test.txt
I want to get end string 'test.txt' from above line and length of that end string will change and it always start after '/'.
Thanks,
Visu (7 Replies)