I suppose the problem being the "echo" statement. It is fed the content of the variable "$line" and interprets it. "\n" and "\t" in your example are control characters, though. "\n" is "newline", "\t" is tab.
Anyhow, your implementation isn't all too good anyway, because you use several commands and a pipeline to do what shell exansion could do too - at considerably less computing costs:
Change your code accordingly and it should not only work but run faster too.
An independent observation: DO NOT use backticks any more. They are deprecated and the shell only understands them for backward compatibility issues. Use the modern "$(...)" instead, which is a lot more flexible, can be nested, can be quoted, ...
Another hint: in case you write for Korn shell you might consider using file descriptors instead of redirection. Instead of:
Hi All,
I am looking for a solution to capture any ASCII control character in a file
( where the ASCII control character is in decimal value from 0 to 31 and 127
( Hex value from 00 to 1F and 7F ) ) by returning any affected lines.
The intended good file should contain "ASCII printable... (5 Replies)
Hi All,
I am very new to Shell scripting...
I got a requirement.
I will have few text files(data files) in a particular directory. they will be with .txt extension. With same name, but with a different extension control files also will be there. For example, Sample_20081001.txt is the data... (4 Replies)
can any one say about command to find "^M" (Control M)characters in a unix text file.
^M comes when a file ftped from windows to unix without using bin mode.
I need the command to find lik this,
ex.txt:
------------------------------
...,name,time^M
go^M
...file,end^M... (5 Replies)
Hi,
I have one file, say file 1, that has data like below where 19900107 is the date,
19900107 12 144 129 0.7380047
19900108 12 168 129 0.3149017
19900109 12 192 129 3.2766666E-02
... (3 Replies)
I am getting error when loading data file using ctl file. I get this error only when there is special character.
Below is some data.
DataFile=>
company_id|ciu_id|english_name|iso_country_code|active|partner_name
1-2JT-122||Expert Järvenpää|FI|A|Expert Järvenpää
Control File=>
LOAD DATA... (1 Reply)
In a 10-50GB file , at end of file there is Control-z character
tried the below options,
1. perl -p -i -e 's/^Z//g' new.txt
2. perl -0777lwi -032e0 new.txt
and Sed command, dos2unix etc
it takes more time to remove the control-z. need a command or perl program to GO TO LAST LINE OF FILE ... (7 Replies)
in a file we are getting control character in a file , is there any way that they can be removed once we have the file
for eg.
BEGIN-PROCEDURE INITIALIZE
^M
LET #row_count = 0^M
^M
^M (2 Replies)
Hi All,
i have a requirement where i need to format the input RAW file ( which is CSV) by using another mapping file(also CSV file). basically i am getting feed file with dynamic headers by using mapping file (in that target field is mapped with source filed) i have to convert the raw file into... (6 Replies)
Hello,
I have a file with the below contents :
Policy Name: Backup_bkp
Policy Type: Catalog_bkp
Active: yes
Effective date: 08/07/2013 02:02:12
Mult. Data Streams: no
Client Encrypt: no
Checkpoint: no
Policy Priority: ... (11 Replies)
Discussion started by: rahul2662
11 Replies
LEARN ABOUT PHP
exec
EXEC(3) 1 EXEC(3)exec - Execute an external programSYNOPSIS
string exec (string $command, [array &$output], [int &$return_var])
DESCRIPTION exec(3) executes the given $command.
PARAMETERS
o $command
- The command that will be executed.
o $output
- If the $output argument is present, then the specified array will be filled with every line of output from the command. Trailing
whitespace, such as
, is not included in this array. Note that if the array already contains some elements, exec(3) will append
to the end of the array. If you do not want the function to append elements, call unset(3) on the array before passing it to
exec(3).
o $return_var
- If the $return_var argument is present along with the $output argument, then the return status of the executed command will be
written to this variable.
RETURN VALUES
The last line from the result of the command. If you need to execute a command and have all the data from the command passed directly back
without any interference, use the passthru(3) function.
To get the output of the executed command, be sure to set and use the $output parameter.
EXAMPLES
Example #1
An exec(3) example
<?php
// outputs the username that owns the running php/httpd process
// (on a system with the "whoami" executable in the path)
echo exec('whoami');
?>
NOTES
Warning
When allowing user-supplied data to be passed to this function, use escapeshellarg(3) or escapeshellcmd(3) to ensure that users can-
not trick the system into executing arbitrary commands.
Note
If a program is started with this function, in order for it to continue running in the background, the output of the program must be
redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.
Note
When safe mode is enabled, you can only execute files within the safe_mode_exec_dir. For practical reasons, it is currently not
allowed to have .. components in the path to the executable.
Warning
With safe mode enabled, the command string is escaped with escapeshellcmd(3). Thus, echo y | echo x becomes echo y | echo x.
SEE ALSO system(3), passthru(3), escapeshellcmd(3), pcntl_exec(3), backtick operator.
PHP Documentation Group EXEC(3)