First, I assume you mean awk command in the generic sense, rather than command awk literally (which does something entirely different).
If the awk script fails for any reason, the contents of file will be destroyed. Depending on the operating system and shell you're using, echo "$var" may modify the contents of file if the expansion of $var contains any backslash (\) characters or starts with a minus-sign (-) character.
This User Gave Thanks to Don Cragun For This Post:
First, I assume you mean awk command in the generic sense, rather than command awk literally (which does something entirely different).
If the awk script fails for any reason, the contents of file will be destroyed. Depending on the operating system and shell you're using, echo "$var" may modify the contents of file if the expansion of $var contains any backslash (\) characters or starts with a minus-sign (-) character.
thanks for your explications, i'm not an expert as you, i use always the same OS (OSX) and the same shell (bash 3.2), in my case i think that $var don't modify the contents of file
message to MadeInGermany
I never work with bigger file text.
thanks for your explications, i'm not an expert as you, i use always the same OS (OSX) and the same shell (bash 3.2), in my case i think that $var don't modify the contents of file
... ... ...
Thx
Hi protocomm,
Try the following script:
on OS X using bash when file contains:
I think you will find that it changes the contents from the three characters -, n, and <newline> to an empty file.
On some other operating systems, much more common file contents could be converted in ways (some obvious and some subtle) that would render working shell scripts or correct C source code contained in file into streams of syntax errors.
Hi protocomm,
Try the following script:
on OS X using bash when file contains:
I think you will find that it changes the contents from the three characters -, n, and <newline> to an empty file.
On some other operating systems, much more common file contents could be converted in ways (some obvious and some subtle) that would render working shell scripts or correct C source code contained in file into streams of syntax errors.
I try your line code and after the treatment and put
in the file, the contents not change, the file is the same that before
i have the same result that you demonstrate…
But if i put something after the -n\n , the file is not empty…
In fact i don't understand that you want to explain for me, sorry…, i don't understand the interest…
In which case i will have a file just with -n\n as content ?
i have the same result that you demonstrate...
But if i put something after the -n\n , the file is not empty...
In fact i don't understand that you want to explain for me, sorry..., i don't understand the interest...
In which case i will have a file just with -n\n as content ?
The point is that in message #13 in this thread, you implied that
are equivalent.
I want the people with less experience reading this thread to understand that although they may be equivalent in some cases on some systems; in cases of resource shortages, I/O errors, or power failures and (depending on the size of file, the contents of the file, and the version of echo you're using), some or all of the contents of file may be destroyed by the code shown in red while the code shown in green would preserve the original contents of file or atomically replace the contents of file with the results of any changes made by the awk script
(And, yes, I know that undetected hardware errors could destroy the contents of file with either method. But, we all hope that we don't have to worry about those cases too often.)
This User Gave Thanks to Don Cragun For This Post:
Hi
I am trying to run a sed command within a script..unfortunately it wasn't written on Solaris so doesn't work. Can anyone help with the correct coding please?
It is:
sed -i '1i ROWID;ORDER_ID;JOB_NAME;ORDER_TABLE' ${OUTFILE} (4 Replies)
Hello,
I have a file with multiple paragraphs/sections each starting with word "Handle" and if I grep for a pattern, I should get contents of entire section/para (not just line). Please advise, thanks!
#script.sh file.txt "System Information"
Handle 0x0001
DMI type 1, 27 bytes.
... (9 Replies)
Hi,
I want to insert a value (x) in the 3rd position of each line in a file like below
a|b|c|d|1
a|b|c|d
a|b|c|d|e|1
a|b|cso that output file looks like
a|b|x|c|d|1
a|b|x|c|d
a|b|x|c|d|e|1
a|b|x|cI can do that using perl as below
#!/usr/bin/perl -w
use strict;
#inserting x at... (5 Replies)
Hello.
I have a config file (/etc/my_config_file) which may content :
#
# port for HTTP (descriptions, SOAP, media transfer) traffic
port=8200
# network interfaces to serve, comma delimited
network_interface=eth0
# set this to the directory you want scanned.
# * if have multiple... (6 Replies)
Just posted on another fellow's question using ed, but I wanted to know about doing it with sed on Unix. For example - I have a file of an unknown length, but I want to add a line after the shell declaration (Line 2). If possible, I'd like the example to be able to just substitute in a number and... (2 Replies)
Hi Guys,
can any one know how to replace the string by newline using sed ?
i dont need any other solution. I am very curious to know this in sed.
Input:
one,two,three
Output
one
two
three
we can acheive this by awk but in sed ?,
awk '{gsub(/\,/,"\n");print;}' File (6 Replies)
Hi,
I have to insert a line having variables using sed. But the variables are not getting substituted within sed.
Ex:
n=2
sed $n' i\
hi' file
This works. But the below code does not work.
n=2
line=hello
sed $n' i\
$line' file
The above code inserts '$line' in the 2nd line of the... (9 Replies)
Hi I'm new to sed, and need to add characters into a specific location of a file, the fileds are tab seperated.
text <tab> <tab> text <tab> text EOL
I need to add more characters to the line to look like this:
text <tab> <tab> newtext <tab> text <tab> text EOL
Any ideas? (2 Replies)
Hi there,
may someone easily help me on this :
I want to insert a text in a specific line number like :
linenumb2start=`cat memory_map.dld | nl -ba | egrep -i "label" | cut -f1`
line2insert=`expr $linenumb2start + 2`
and now I need to replace something like {} with {comment} at... (8 Replies)