Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
55
votes
5
answers
73274
views
Replace all newlines to space except the last
How can I replace all newlines with space except the last newline. I can replace all newline to space using `tr` but how I can do it with some exceptions?
How can I replace all newlines with space except the last newline.
I can replace all newline to space using
tr
but how I can do it with some exceptions?
user59930
Feb 8, 2014, 08:36 PM
• Last activity: Apr 16, 2025, 07:42 AM
1
votes
12
answers
13270
views
Replace comma with newline following with just a command and space
I have a list like so. blue-image1.jpg, blue-image2.jpg, blue-image3.jpg red-image1.jpg, red-image2.jpg, red-image3.jpg It's was originally a csv format but I added newlines because they needed a prefix at first. Now I need to put them together again so it becomes like this. blue-image1.jpg,blue-ima...
I have a list like so.
blue-image1.jpg,
blue-image2.jpg,
blue-image3.jpg
red-image1.jpg,
red-image2.jpg,
red-image3.jpg
It's was originally a csv format but I added newlines because they needed a prefix at first. Now I need to put them together again so it becomes like this.
blue-image1.jpg,blue-image2.jpg,blue-image3.jpg
red-image1.jpg,red-image2.jpg,red-image3.jpg
I tried
cat list.txt | tr ',\n' ','
and cat list.txt | sed 's/,\n/,/g'
but neither seem to work properly.
johnny538
(11 rep)
Dec 11, 2016, 03:53 PM
• Last activity: Jul 7, 2024, 12:46 AM
-1
votes
1
answers
63
views
sed and tr not replacing mystery control character
``` root@calleva:~# echo "f" > file root@calleva:~# f=$(<file) root@calleva:~# echo "$f" f root@calleva:~# echo "$f" | tr -c '[:alpha:]' '_' f_root@calleva:~# echo "$f" | tr -c '[:alpha:]' -d tr: when translating with complemented character classes, string2 must map all characters in the domain to o...
root@calleva:~# echo "f" > file
root@calleva:~# f=$(
So it appears that tr
can do only one of -c
and -d
and not both at the same time?
And sed
simply doesn't work?
Richard Barraclough
(550 rep)
May 9, 2024, 04:32 PM
• Last activity: May 9, 2024, 05:05 PM
0
votes
1
answers
101
views
Need help with a script that mv (renames) filenames that require single quotes in ls output or file operations
I need help with a script that mv (renames) filenames that are shown with single quotes in ls output or files that require single quotes for file operations. The script will be used to rename all files in a directory. I created a batch of test files using every displayable non-alphanumeric character...
I need help with a script that mv (renames) filenames that are shown with single quotes in ls output or files that require single quotes for file operations. The script will be used to rename all files in a directory. I created a batch of test files using every displayable non-alphanumeric character I can type on my US keyboard (with the exceptions of 'a/b' and 'a'b') to test the script with:
touch 'a~b' 'a`b' 'a!b' 'a@b' 'a#b' 'a$b' 'a%b' 'a^b' 'a&b' 'a*b' 'a(b' 'a)b' 'a-b' 'a_b' 'a+b' 'a=b' 'a{b' 'a}b' 'a[b' 'a]b' 'a|b' 'a\b' 'a:b' 'a;b' 'a"b' 'ab' 'a,b' 'a.b' 'a?b' 'a b'
So now my test directory contains:
psilo@deb:~/sh$ ls
'a$b' a#b 'a)b' a-b 'ab' 'a\b' 'a`b' a~b
'a"b' 'a(b' a,b 'a;b' 'a?b' a]b a{b filenametweak.sh
In addition, I have the personal preference to tr a space to a . and an underscore to a .
My script is:
#!/bin/bash
for file in *; do echo mv "$file"
echo $file | tr ' ' '.' | tr '_' '.' | tr -cd '\043\045\053-\056\060-\072\077\100-\132\135\141-\173\175\176'
; done
I am attempting to remove all of the characters from the input stream via the tr command (with -c & -d arguments) other than the ASCII octal values that are shown between the single quotes. This should produce an output with my "problem" ASCII characters removed (those that require the filename to be wrapped in single quotes on the ls output above).
I have included the echo command before the mv "$file" in the script to test the output before pulling the trigger.
However, when the script encounters the '?' or '*' characters in the filename, it produces undesirable output:
psilo@deb:~/sh$ ./filenametweak.sh
mv a$b ab
mv a b a.b
mv a!b ab
mv a"b ab
mv a#b a#b
mv a%b a%b
mv a&b ab
mv a(b ab
mv a)b ab
mv a*b ab.a.b.ab.ab.a#b.a%b.ab.ab.ab.ab.a+b.a,b.a-b.a.b.a:b.ab.ab.ab.ab.a?b.a@b.ab.ab.a]b.ab.a.b.ab.a{b.ab.a}b.a~b
mv a+b a+b
mv a,b a,b
mv a-b a-b
mv a.b a.b
mv a:b a:b
mv a;b ab
mv ab ab
mv a?b ab.a.b.ab.ab.a#b.a%b.ab.ab.ab.ab.a+b.a,b.a-b.a.b.a:b.ab.ab.ab.ab.a?b.a@b.ab.ab.a]b.ab.a.b.ab.a{b.ab.a}b.a~b
mv a@b a@b
mv a[b ab
mv a\b ab
mv a]b a]b
mv a^b ab
mv a_b a.b
mv a`b ab
mv a{b a{b
mv a|b ab
mv a}b a}b
mv a~b a~b
mv filenametweak.sh filenametweak.sh
How can I resolve the problem when filenames with * or ? are encountered - OR - how can I achieve my mv rename intent in bash via a different and/or better method?
Psilospiral
(51 rep)
Oct 14, 2023, 07:35 PM
• Last activity: Mar 12, 2024, 03:03 PM
18
votes
3
answers
19177
views
Main difference between tr (translate) to sed and awk
AFAIC both `sed` and `awk` are general purpose text processing utilities with whom a user can get quite similar results, in a slightly different syntax: With both, a user could add, replace/translate and delete content in a file. What is the main difference between these two general purpose text pro...
AFAIC both
sed
and awk
are general purpose text processing utilities with whom a user can get quite similar results, in a slightly different syntax:
With both, a user could add, replace/translate and delete content in a file.
What is the main difference between these two general purpose text processing utilities and the tr
text processing utility?
I assume that tr
's functionality is included in both sed
and awk
so it is just narrowed to the specific context of **replacing** one string in another, but I'm not sure I'm accurate here or **translating** it to another.
Arcticooling
(1 rep)
Mar 3, 2018, 09:18 PM
• Last activity: Dec 5, 2023, 01:32 PM
0
votes
4
answers
1790
views
How to do a sed substitution (s///g) based on a list? I need to swap multiple words, with other corresponding words
I don't think this question has been asked before, so I don't know if `sed` is capable of this. Suppose I have a bunch of numbers in a sentence that I need to expand into words, a practical example being to swap the numbered citations in a typical essay into MLA format: `essay.txt`: Sentence 1 [1]....
I don't think this question has been asked before, so I don't know if
sed
is capable of this.
Suppose I have a bunch of numbers in a sentence that I need to expand into words, a practical example being to swap the numbered citations in a typical essay into MLA format:
essay.txt
:
Sentence 1 . sentence two . Sentence three.
Key.txt
(this is a tab delimited file):
1 source-one
2 source-two
3 source-three
...etc
Expected Result.txt
:
Sentence 1 [source-one]. sentence two [source-one][source-two]. Sentence three[source-one][source-three]
Here's my pseudocode attempt, but I don't understand enough about sed
or tr
to do it right:
cat essay.txt | sed s/$(awk {print $1} key.txt)/$(awk {print $2} key.txt)/g
PS: If there's a trick in notepad++ for mass find-and-replace using multiple terms, that'd be great. As it is, it seems like find-and-replace only works for one term at a time, but I need a way to do it en masse for many terms at once.
Tom
(163 rep)
Sep 22, 2016, 03:36 AM
• Last activity: Dec 1, 2023, 09:15 AM
-1
votes
2
answers
4849
views
How does the `tr` command work?
I was playing around with `tr` and got some unexpected results. What is happening in these situations? I don't understand what is happening under the hood, or perhaps I'm not using this command correctly. ### Example A ``` echo '0123456789' | tr [:digit:] '12' 1222222222 ``` --- ### Example B1 ``` e...
I was playing around with
tr
and got some unexpected results. What is happening in these situations? I don't understand what is happening under the hood, or perhaps I'm not using this command correctly.
### Example A
echo '0123456789' | tr [:digit:] '12'
1222222222
---
### Example B1
echo '1111111111' | tr [:digit:] '12'
2222222222
### Example B2
echo '1111111111' | tr '1' '12'
1111111111
---
### Example C1
Works as expected.
echo '0123456789' | tr '5' 'x'
01234x6789
### Example C2
I expected this to produce 01234xx6789
maybe, or it somehow explains all these examples - in that only the original character can be replaced (additional characters cannot be added).
echo '0123456789' | tr '5' 'xx'
01234x6789
BadHorsie
(141 rep)
Nov 22, 2023, 03:43 PM
• Last activity: Nov 22, 2023, 06:17 PM
2
votes
0
answers
99
views
The paste command is outputing tabs instead of new lines when used with process substitution
The first command below produces each number on a separate line, and I would expect the second command to do the same thing because the only difference between the two is that we are using `echo '1 2 3'` and `echo {1..3}` (both of which produce the same output). **But, the second command produces th...
The first command below produces each number on a separate line, and I would expect the second command to do the same thing because the only difference between the two is that we are using
echo '1 2 3'
and echo {1..3}
(both of which produce the same output). **But, the second command produces the numbers that are separated by tabs instead of new lines. Why?**
Furthermore, notice that the only difference between the second and the third commands is that we are passing the result to paste
via process substitution, but without that, it shows the expected result, which could imply that it is a paste
related issue, but I don't quite see what the issue is.
§ paste /dev/null
1
2
3
§ paste /dev/null
1
2
3
---
If it matters, here are the versions of the tools:
§ which tr paste
/usr/local/opt/coreutils/libexec/gnubin/tr
/usr/local/opt/coreutils/libexec/gnubin/paste
§ tr --version
tr (GNU coreutils) 9.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later .
Written by Jim Meyering.
§ paste --version
paste (GNU coreutils) 9.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later .
Written by David M. Ihnat and David MacKenzie.
§ bash --version
bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin20)
Copyright (C) 2007 Free Software Foundation, Inc.
§ sw_vers
ProductName: macOS
ProductVersion: 11.7.10
BuildVersion: 20G1427
I am on macOS, but use GNU utils installed via brew
.
---
Addition debug information requested by comments with set -x
active:
§ paste <(echo {1..3} | tr ' ' '\t' | tr '\t' '\n')
+ paste /dev/fd/63 /dev/fd/62 /dev/fd/61
++ echo 1
++ echo 3
++ tr ' ' '\t'
++ tr ' ' '\t'
++ tr '\t' '\n'
++ tr '\t' '\n'
++ echo 2
++ tr ' ' '\t'
++ tr '\t' '\n'
1 2 3
§ paste <(echo {1..3} | tr ' ' '\n')
+ paste /dev/fd/63 /dev/fd/62 /dev/fd/61
++ echo 1
++ tr ' ' '\n'
++ echo 2
++ echo 3
++ tr ' ' '\n'
++ tr ' ' '\n'
1 2 3
§ echo {1..3} | tr ' ' '\n' | paste
+ tr ' ' '\n'
+ echo 1 2 3
+ paste
1
2
3
And hexdump
output:
§ paste <(echo {1..3} | tr ' ' '\n') | hexdump -C
00000000 31 09 32 09 33 0a |1.2.3.|
00000006
§ echo {1..3} | tr ' ' '\n' | paste | hexdump -C
00000000 31 0a 32 0a 33 0a |1.2.3.|
00000006
sudocracy
(221 rep)
Nov 3, 2023, 12:27 AM
• Last activity: Nov 3, 2023, 10:28 AM
0
votes
5
answers
837
views
How to merge lines in groups of three
I have a file containing the below pattern, up to 2000 lines. For every group of three lines, the pattern repeats with different numerical values, but text values at the beginning are common up to the end of the file. Here I need to merge set of three lines Input like below ABC 1223334 Days 34467854...
I have a file containing the below pattern, up to 2000 lines. For every group of three lines, the pattern repeats with different numerical values, but text values at the beginning are common up to the end of the file.
Here I need to merge set of three lines
Input like below
ABC 1223334
Days 344678544324677
Base 45666
ABC 1234565
Days 234567899765443
Base 456643
Need output looks like
ABC 1223334 Days 344678544324677 Base 45666
ABC 1234565 Days 234567899765443 Base 456643
C S Pallapu
(41 rep)
Dec 12, 2022, 06:38 PM
• Last activity: Oct 10, 2023, 10:43 AM
55
votes
4
answers
144605
views
Removing all spaces, tabs, newlines, etc from a variable?
This is the error I am getting and it's failing because of a variable whose value is supposed to be 2 (I am getting this using a `select * from tabel`). I am getting spaces in that variable. + 0 != 2 ./setjobs[19]: 0: not found. How do I remove all those spaces or a newline from that variable? Can `...
This is the error I am getting and it's failing because of a variable whose value is supposed to be 2 (I am getting this using a
select * from tabel
).
I am getting spaces in that variable.
+ 0 !=
2
./setjobs: 0: not found.
How do I remove all those spaces or a newline from that variable?
Can tr
, sed
, or anything help?
This what I am doing:
set_jobs_count=$(echo "set heading off;
select count(*) from oppar_db
where ( oppar_db_job_name, oppar_db_job_rec ) in ($var) ;" | \
sqlplus -s ${OP_ORA_USER}/${OP_ORA_PASS}@$OPERATIONAL_DB_NAME)
---
This works as suggested:
| sed 's/[[:space:]]//g'
But I still obtain a value like :
set_jobs_count=
2
munish
(8227 rep)
Feb 24, 2012, 12:28 PM
• Last activity: Oct 9, 2023, 10:33 AM
1
votes
1
answers
4206
views
How to replace double new line with single using tr?
Given a text, $ cat a.txt Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam at magna sed libero accumsan ultrices. Proin varius tortor risus, at pulvinar quam auctor vitae. Etiam iaculis ipsum quis lacus convallis finibus. Nunc fermentum, nunc sit amet egestas congue, odio quam sollicitud...
Given a text,
$ cat a.txt
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam at magna sed libero accumsan ultrices. Proin varius tortor risus, at pulvinar quam auctor
vitae.
Etiam iaculis ipsum quis lacus convallis finibus. Nunc fermentum, nunc sit amet egestas congue, odio quam sollicitudin velit, quis venenatis augue
nibh sed tortor.
I can't remove that double empty lines using this command.
$ tr '\n\n' '\n' < a.txt
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam at magna sed libero accumsan ultrices. Proin varius tortor risus, at pulvinar quam auctor
vitae.
Etiam iaculis ipsum quis lacus convallis finibus. Nunc fermentum, nunc sit amet egestas congue, odio quam sollicitudin velit, quis venenatis augue
nibh sed tortor.
Replacing single new line with other char works, isn't it strange?
Abdillah
(115 rep)
Jan 5, 2019, 10:44 AM
• Last activity: Sep 29, 2023, 06:21 AM
5
votes
1
answers
425
views
Why does 'tr' with '-c' option and set 2 extension add an unwarranted character to the end?
I wanted to use `tr` to substitute "illegal" characters in a string with a replacement character, where "illegal" characters are all outside of a set of "allowed" characters (_i.e._ they are the complement of the set of allowed characters). However, when using the `-c` option and either the explicit...
I wanted to use
tr
to substitute "illegal" characters in a string with a replacement character, where "illegal" characters are all outside of a set of "allowed" characters (_i.e._ they are the complement of the set of allowed characters). However, when using the -c
option and either the explicit *
repeat specifier or the implicit extension of "set 2", tr
appends an _additional_ instance of the replacement character to the output.
**To reproduce**
* Let the "allowed" characters be a-n
, specified literally as abcdefghijklmn
.
* Let the replacement character be z
.
* Let the input string be either hell
or hello
. The expected output string is then hell
and hellz
, respectively.
**Demonstration**
1. Illegal characters present, implicit set 2 extension
-shellsession
$ echo "hello" | tr -c 'abcdefghijklmn' 'z'
hellzz
The expected output is hellz
.
2. Only allowed characters present, implicit set 2 extension
-shellsession
$ echo "hell" | tr -c 'abcdefghijklmn' 'z'
hellz
The expected output is hell
.
3. Illegal characters present, explicit set 2 extension
-shellsession
$ echo "hello" | tr -c 'abcdefghijklmn' '[z*]'
hellzz
The expected output is hellz
.
4. Only allowed characters present, explicit set 2 extension
-shellsession
$ echo "hell" | tr -c 'abcdefghijklmn' '[z*]'
hellz
The expected output is hell
.
5. The same happens when I use a here-string instead of echo-pipe (actually, the here-string was the construct I used when I stumbled upon this effect for the first time):
-shellsession
$ tr -c 'abcdefghijkl' '[z*]' <<< "hello"
hellzz
Why does tr
append an additional z
here?
This is on Linux, with bash, UTF-8 locale, and tr
from both GNU coreutils 8.25 and 8.30.
AdminBee
(23588 rep)
Aug 25, 2023, 11:16 AM
• Last activity: Aug 26, 2023, 07:08 AM
0
votes
2
answers
184
views
How to combine tr with xargs and cut to squeeze repeats
The top answer to [this question](https://unix.stackexchange.com/questions/109835/how-do-i-use-cut-to-separate-by-multiple-whitespace) demonstrates that `cut` can be used with `tr` to cut based on repeated spaces with ```sh < file tr -s ' ' | cut -d ' ' -f 8 ``` I want to get the remotes of several...
The top answer to [this question](https://unix.stackexchange.com/questions/109835/how-do-i-use-cut-to-separate-by-multiple-whitespace) demonstrates that
cut
can be used with tr
to cut based on repeated spaces with
< file tr -s ' ' | cut -d ' ' -f 8
I want to get the remotes of several Git repos in a directory and am attempting to extract the remote URL fields from each with the following:
ls | xargs -I{} git -C {} remote -vv | sed -n 'p;n' | tr -s " " | cut -d ' ' -f1
However, this results in (for example) the following output, where I can see that two consecutive spaces (Unicode code point 32) are retained:
origin https://github.com/jik876/hifi-gan.git
origin https://github.com/NVIDIA/NeMo.git
origin https://github.com/NVIDIA/tacotron2.git
(I have also using xargs
with tr
)
The desired output is a list of URLs, like:
https://github.com/jik876/hifi-gan.git
https://github.com/NVIDIA/NeMo.git
https://github.com/NVIDIA/tacotron2.git
What am I missing here?
Anil
(221 rep)
Aug 22, 2023, 09:42 AM
• Last activity: Aug 23, 2023, 01:45 AM
0
votes
1
answers
207
views
Transforming a filename with 'tr' using RegEx doesn't work
I want to use the `tr` command to rename something like `filename.ext` to `someName.ext`. To do that I've tried ``` echo "filename.ext" | tr -c ".a-z" "someName"` ``` to replace the _complement_ (`-c`) of the filename extension (specified as period, followed by lower-case letters) with the new basen...
I want to use the
tr
command to rename something like filename.ext
to someName.ext
.
To do that I've tried
echo "filename.ext" | tr -c ".a-z" "someName"`
to replace the _complement_ (-c
) of the filename extension (specified as period, followed by lower-case letters) with the new basename.
However, it does not work - tr
isn't recognizing it as a complement of a period followed by small case alphabets to be replaced by something else.
What am I missing here?
Abhishek A Udupa
(111 rep)
Jul 20, 2023, 10:29 AM
• Last activity: Jul 20, 2023, 02:43 PM
0
votes
3
answers
3020
views
sed: remove extra whitespace to single whitespace between strings while leaving leading tabs intact
I have a code: 1 /** 2 a b c 3 **/ 4 int main() { 5 int x; 6 if ( condition) { 7 return x; 8 } 9 } I need to change multiple whitespaces between tokens or strings to single whitespace eg in line 7 but comments (line 2) should not be affected nor the leading tabs in the code. So, the output should be...
I have a code:
1 /**
2 a b c
3 **/
4 int main() {
5 int x;
6 if ( condition) {
7 return x;
8 }
9 }
I need to change multiple whitespaces between tokens or strings to single whitespace eg in line 7 but comments (line 2) should not be affected nor the leading tabs in the code. So, the output should be:
1 /**
2 a b c
3 **/
4 int main() {
5 int x;
6 if ( condition) {
7 return x;
8 }
9 }
I tried using 'tr':
~$ tr -s " " < file
but it changed line 2 as well as removed leading tabs in line 5 to line 8. Can it be done using sed
?
Windy Day
(33 rep)
Sep 24, 2018, 03:27 AM
• Last activity: Jun 20, 2023, 01:57 AM
7
votes
6
answers
7119
views
How to change any text to Proper Case and Sentence case using tr?
According to https://caseconverter.com/ > “Upper Case” WHICH CONVERTS ALL THE LETTER INTO CAPITALS LIKE THIS. > > “Lower Case” which converts all the letters into small letters like > this. > > “Proper Case” Which Converts The Text So Every Word Has Its First > Letter Capitalised Like This > > “Sent...
According to https://caseconverter.com/
> “Upper Case” WHICH CONVERTS ALL THE LETTER INTO CAPITALS LIKE THIS.
>
> “Lower Case” which converts all the letters into small letters like
> this.
>
> “Proper Case” Which Converts The Text So Every Word Has Its First
> Letter Capitalised Like This
>
> “Sentence Case”. This capitalises the first letter of each sentence,
> and converts the rest of the text to lower case. So the first letter
> after every full stop is automatically converted into a capital
> letter.
The first two can be accomplish easily with
tr
command.
user@linux:~$ tr [:lower:] [:upper:] <<< eXaMPLe
EXAMPLE
user@linux:~$
user@linux:~$ tr [:upper:] [:lower:] <<< eXaMPLe
example
user@linux:~$
or
user@linux:~$ tr [a-z] [A-Z] <<< eXaMPLe
EXAMPLE
user@linux:~$
user@linux:~$ tr [A-Z] [a-z] <<< eXaMPLe
example
user@linux:~$
What about the last two which are "Proper Case" and "Sentence Case"?
Is it possible?
If yes, please let me know.
If not, what is the alternative?
user264359
Nov 30, 2019, 07:16 AM
• Last activity: Jun 8, 2023, 01:47 AM
124
votes
7
answers
221961
views
Convert file contents to lower case
I have `temp` file with some lower-case and upper-case contents. ## Input ## Contents of my `temp` file: hi Jigar GANDHI jiga I want to convert all **upper to lower**. ## Command ## I tried the following command: sed -e "s/[A-Z]/[a-z]/g" temp but got wrong output. ## Output ## I want it as: hi jigar...
I have
temp
file with some lower-case and upper-case contents.
## Input ##
Contents of my temp
file:
hi
Jigar
GANDHI
jiga
I want to convert all **upper to lower**.
## Command ##
I tried the following command:
sed -e "s/[A-Z]/[a-z]/g" temp
but got wrong output.
## Output ##
I want it as:
hi
jigar
gandhi
jiga
What needs to be in the *substitute* part of argument for sed
?
JigarGandhi
(5100 rep)
Dec 5, 2014, 07:32 AM
• Last activity: Apr 13, 2023, 10:25 AM
47
votes
2
answers
66863
views
tr complains of “Illegal byte sequence”
I'm brand new to UNIX and I am using Kirk McElhearn's "The Mac OS X Command Line" to teach myself some commands. I am attempting to use `tr` and `grep` so that I can search for text strings in a regular MS-Office Word Document. $ tr '\r' '\n' robomechanoid:Position-Paper-Final-Draft robertjralph$ tr...
I'm brand new to UNIX and I am using Kirk McElhearn's "The Mac OS X Command Line" to teach myself some commands.
I am attempting to use
tr
and grep
so that I can search for text strings in a regular MS-Office Word Document.
$ tr '\r' '\n'
robomechanoid:Position-Paper-Final-Draft robertjralph$ tr '\r' '\n' < Position-Paper-Final-Version.docx | grep DeCSS
tr: Illegal byte sequence
robomechanoid:Position-Paper-Final-Draft robertjralph$
I've actually run the same line on a script that I created in vi
and it does the search correctly.
user74886
(471 rep)
Jul 8, 2014, 10:14 PM
• Last activity: Mar 25, 2023, 05:41 PM
5
votes
3
answers
503
views
Processing a continuous single line of data with stream processing in bash pipeline?
I am debugging an embedded server that outputs a continuous single line of text to a specified network port. There is no newline anywhere in the stream but it is text data and I would like to format it as it outputs. I have tried using tr (translate) to swap a character in the stream for a newline w...
I am debugging an embedded server that outputs a continuous single line of text to a specified network port. There is no newline anywhere in the stream but it is text data and I would like to format it as it outputs. I have tried using tr (translate) to swap a character in the stream for a newline which works, however it is impossible to find a unique single character that can always be sensibly replaced by a newline. My initial thought was to use sed to add a newline character to a pattern of 2-3 characters but because sed is line based and the stream is a never ending single line, sed will never complete the process! Is there a non line based sed alternative?
stmfunk
(193 rep)
Feb 15, 2023, 11:13 AM
• Last activity: Feb 20, 2023, 01:24 PM
1
votes
3
answers
3173
views
getting a list of all lowercase words in a file
I'm trying to get a list of all lowercase words in a file. This far I've gotten to the point of getting a list with the command line cat filename.txt | tr ' ' \\n | grep -w '[[:lower:]]*' | sort -u | less However, this command doesn't get rid of the non-alphabetic characters in the list; I get a lis...
I'm trying to get a list of all lowercase words in a file. This far I've gotten to the point of getting a list with the command line
cat filename.txt | tr ' ' \\n | grep -w '[[:lower:]]*' | sort -u | less
However, this command doesn't get rid of the non-alphabetic characters in the list; I get a list with the form
(which
(which,
about
about,
about.
about:
about;
about?
which
I'm interested only in the lines with only the words. How can I get them with a similar line command?
jarnowy
(200 rep)
Jan 27, 2016, 02:22 AM
• Last activity: Nov 26, 2022, 04:43 AM
Showing page 1 of 20 total questions