i want to make a start.config file by using bat script.
I want to add to my config file that parameter:
StartAgents=9
WITHOUT space at the end of line.
Unfortunately command:
echo StartAgents=9>>C:\start.config
not working, I think that there is "collision" with two characters: "9>"
Command:
echo StartAgents=9 >>C:\start.config
is working, but this is adding space at the end of line in my config file - i dont want that.
Any ideas how to do that?
I want to add line StartAgents=9 without space af the end of line.
want:
StartAgents=9
dont want:
StartAgents=9
You have to escape the number, so that it isn't interpreted by CMD.EXE as a file descriptor number.
Then you can add the >> redirection directly after the number to not insert a trailing space.
Example:
echo StartAgent=^9>>test.txt
Related Information:
Omitting trailing space
File Descriptor Usage
Related
I have a centos server. I cloned a GitHub repository. And I have .txt file in that repository which contains 1 line. For some reason it does that:
[root#0-0-0-0 Some]# cat some.txt
some text[root#0-0-0-0 Some]#
And also while read i; do echo "$i"; done < some.txt don't see that line. What could cause that? And how to avoid it. If I edit it with vim adding a new line and then deleting that new line (so it still contains only one line) it starts to work properly.
The text file has no newline character at the end of it. Some programs will treat it as a valid text file whose last line doesn't happen to end in a newline. Others (apparently including bash's built-in read command, at least by default) will treat it as invalid, and perhaps ignore the last line (which isn't considered a "line" because it's not marked as one).
vim's default behavior is to quietly add a newline to the end of a file if you modify and save it.
You can add a newline to a file that lacks one by editing it with vim (or another editor that behaves similarly), or by adding it from the shell:
echo '' >> some.txt
In general, it's a good idea to ensure that text files end in a newline character in the first place, at least if they're intended to be used on UNIX-like systems.
I have a list of lines in variable (1,3,8,9). That list shows which lines I need to delete from a text file. which function I can use to delete specific lines number?
Thank you so much for your respond
# set -vx
lines2del="(1,3,8,9)"
sedCmds=${lines2del//,/d;}
sedCmds=${sedCmds/(/}
sedCmds=${sedCmds/)/}
sedCmds=${sedCmds}d
sed -i "$sedCmds" file
Remove the # before set -vx to see the debug/trace for each cmd as it is executed.
If you don't really have ( ) (parens) around your data, fix the line2del variable and remove the second and third sedCmds= lines.
IHTH
set NUMBER=0
echo 3.3.3.%NUMBER% > "file.txt"
after running this command the content of file.txt is 3.3.3.0 with extra space after the 0
I would like to remove the extra space, how this can be done?
EDIT
I following the answer of bgoldst the extra space is gone, however now I have extra line break. I want to remove it
I found some answers for solving the extra line, however I don't want space not new line in the file
Building on the answer by bgoldst
To remove the space and the line feed:
<nul set /p=3.3.3.%NUMBER%>file.txt
See Windows batch: echo without new line for more information.
The space is introduced by the echo command because there is a space between the %NUMBER% variable and the > redirection operator. The echo command respects trailing whitespace in its command-line.
Thus, you can solve this by removing that space (and you can also remove the quotes, as well as the space between the > and the file.txt, since they are not necessary):
echo 3.3.3.%NUMBER%>file.txt
I have a bash script that runs and outputs to a text file however the colour codes it uses are also included what i'd like to know is how to remove them from the file, ie
^[[38;1;32mHello^[[39m
^[[38;1;31mUser^[[39m
so I just want to be left with Hello and User, so something like sed -r "special characters" from file A save to file B
sed 's/\^\[\[[^m]*m//g'
remove (all) part of line starting with ^[[ until first m
Some like this:
awk '{sub(/\^\[\[38;1;[0-9][0-9]m/,x);sub(/\^\[\[39m/,x)}1'
Hello
User
Using a batch file (.bat), I'm making a script that requires dynamic paths so that it can work on multiple computers. My problem is when I echo something to a file, it adds a line and an a return carriage.
Say I have a text file named foo.txt in the directory of the batch file, and its contents are completely empty.
In the batch file, I run:
echo test > foo.txt
The contents of foo.txt will be:
L1: foo
L2:
There would be a space after foo in the first line and a second empty line. Now, this would be completely okay and I would entirely ignore it, but filename paths do not ignore it.
importing text from foo.txt like so:
set /p foo=< foo.txt
...and then:
set /p name=< C:\A.D.V.E.N.T.U.R.E.\test\%foo%\test2.txt
...would be interpreted as:
set /p name=< C:\A.D.V.E.N.T.U.R.E.\test\foo \test2.txt
Including an unwanted space. Is there anyway to make it so you can write text to a file without a space, or a command one could use to delete the carriage return and the space?
You can also use parentheses to make sure unwanted space is not included in the output:
(echo test) >foo.txt
The data should be test, not foo
Clasically, try
>foo.txt echo test
but make sure that there are no trailing spaces after test.
(to APPEND to foo.txt use >> in place of >)
above given answers works.
But, the actual reason I found for it was the space before >
So, instead of
echo test > foo.txt
it must be
echo test> foo.txt
NOTE. Don't put any space between test and >. This, results in a trailing space.