All Questions
32 questions
2
votes
9
answers
2k
views
Why grep does not work properly in this case?
Consider a file file2.txt having the following content:
P 89 24 -1.5388040474568784e+01 7.4421775186012660e+00 -1.3143195543234219e+03 1.3168884860257754e+03 8.0419002445999993e+01 44 0 0 -97 0
P 122 -...
0
votes
1
answer
463
views
How can I append a specific text at the end of each line in a file?
I have a file called my_file.txt. Its content is as follows:
7rrmC
7rztC
7s63D
7scfA
7sciA
7seuA
7sh3B
7shgA
7sj9N
7sp5A
7sr2B
7stdC
7sv6A
7sybA
7t2yB
7t30B
7t3bE
7t4rA
7t71A
7t8wD
7tacA
7tbsA
7tfmA
...
1
vote
3
answers
460
views
Extract file length from output of 'ls -l' passed back from sftp session
From my local server I only have access to stfp to a remote server where I want to check the size of my backup file as it's being created. So I've been able to write a bit of bash that logs in and ...
0
votes
1
answer
121
views
uncomment the line upon search string while ignoring case in a file
Below is my cron file entries:
#Ansible: test2
*/15 * * * * ansible-playbook https://waybackassets.bk21.net/playbooks/automation/detect401MORTEN/va_action.yml | tee -a https://waybackassets.bk21.net/playbooks/automation/detect401MORTEN/cron.out
# #...
-1
votes
1
answer
67
views
Search & replace for a string separated by whitespace upon substring match found
Below is a sample file content:
cat sample.txt
-server -XX:+UseParallelGC -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+AggressiveHeap -XX:+PrintHeapAtGC -Djava.util.logging.FileHandler....
-1
votes
5
answers
930
views
How to make sure that the last character of each line of a file ends with single quote character
I have a file which has several lines.
I wish to update the file while making sure that the last visible character of each line of the file is a single quote '. In case not, then we should add the ...
0
votes
1
answer
1k
views
How to add single quote at the end of ONLY the last line of a file [duplicate]
I want a non-perl solution where I should be able to append a single quote ' at the last visible (non-escape characters) line of a file and save it back to the file.
cat example.txt
var1: 'funn'
var2: ...
1
vote
5
answers
1k
views
Replace hyphen(s) with underscore(s) within angle brackets in a file
I’m aware of how to replace string;
e.g., replace hyphen with underscore in a file.
However, I wish to replace all hyphens with underscore
for all text that falls within angle brackets in a given file....
2
votes
2
answers
3k
views
In a file to find and replace/change multiple strings in a line with shell script
I am new to shell scripting
What I have is a log file, each line begins like the below entry,
[2021.04.27.17:03:43.813]: ERROR -
[2021.04.27.17:04:36.790]: SUCCESS -
The desired output to a new file ...
1
vote
1
answer
71
views
Replacing lines in one file based of indices in a second file
I have two files:
Ref.txt which contains:
ABCDEFG,15147,1,2,6
HIJKLMN,500,3,4
and Seq.txt which contains:
ABCXXXX
ABCDEXX
IIJKXXX
HIHKXXX
LMNOPQR
BBCDEXX
STUVWXY
I would like to replace the certain ...
0
votes
2
answers
80
views
Find string2 when exist string1 in file
I have a configuration file (from Nagios) with the following structure:
define service{
use pruebaspre-service,srv-pnp
host_name server1.es
servicegroups ...
1
vote
2
answers
7k
views
How to find more than one space and replace it with one space?
I want to find repeated spaces (more than one) and replace them with one space.
I tried:
sed -e 's/ []+/ /g' myfile.txt > myfile2.txt
This resulted in an empty file. Why? and how to achieve my ...
0
votes
0
answers
127
views
How to change the newline position [duplicate]
I have a file that contains string in each line. I used this file as an input in a program that reads them automatically. The program seem to not be able to read the strings correctly. I tried to ...
0
votes
1
answer
668
views
Does sort -u convert case?
If I have a file with some words starting with Capital letters and some starts with Small letters and some start with numbers or special characters. Does using sort -u input > output convert the ...
0
votes
1
answer
758
views
How to extract the first column in a file with multi-character delimeter?
I have a file in which I use a string like <xxxxx> to separate the fields. This was a choice to avoid problems with the comma separated fields and other types of single characters due to the ...