12
votes
how to format a text file in bash with dots from right
Using printf you could use the single quote ' FLAG for the numbers to be grouped with thousands' grouping characters. In the man pages of printf(3):
For some numeric conversions a radix character ("...
10
votes
how to format a text file in bash with dots from right
Another solution is to use numfmt which is included in Debian variants by default
$ WIDTH=20
$ <file.txt tr ' ' '\n' | LC_ALL=el_GR.UTF-8 numfmt --grouping --padding=$WIDTH
1.941.102.556
...
4
votes
how to format a text file in bash with dots from right
Given this input:
$ cat file
1941102556 1750145810 2604905 7000793682 5160065824 3000350768 6449300295 3046118928 12693055728 257664864 13471943769
there's no need to run tr and/or generate a temp ...
4
votes
Accepted
show which of a list of filenames do not exist in a given list of directories
It's a lot easier in zsh:
If you have your list of file names in filenames.txt and list of directories in directories.txt:
#! /bin/zsh -
typeset -U expected=( ${(f)"$(<filenames.txt)"} )
...
3
votes
Accepted
Linux Bash Script - Yes or No - read answer
As I understand it, you want to execute an infinite loop containing your script, and exit from the script when the answer to the prompt is y.
The way to create an infinite loop in bash is using while ...
3
votes
Accepted
how to format a text file in bash with dots from right
I would probably reverse each line, put the dots in, and reverse it back.
$ tr " " "\n" < numbers_in_one_line.txt |
rev |
sed -E 's/(.....
2
votes
Accepted
How do I update the contents of a script including comments (django/settings.py) using echo, printf or grep
Probably, a "here document" is what suits you need best; e.g.,
cat <<'END' >app/hello_django/settings.py
'''
...
'''
import os
...
END
Single quote END to protect the doc from any ...
2
votes
Accepted
Use fallocate with numbers from text file
If you're trying to loop over a sequence of whitespace separated numbers in a single line of list.txt then one way to do so in the bash shell would be to read them into an indexed array:
read -a ...
1
vote
Accepted
join a specific number of files/devices in linear mode together in a linux system
You can use a for loop to iterate from zero to 32, and store the device names in an array.
# you don't show the file, there are programmatic ways to acquire this number
n=33
devices=()
for ((i = 0; i ...
1
vote
Bash: Access variable with another variable
If you're using a modern version of bash you can use variable indirection:
varAble="Hello"
varA="\n"
varBble="World"
varB="END"
for part in A B
do
for var ...
1
vote
How do I update the contents of a script including comments (django/settings.py) using echo, printf or grep
Your approach would also work, but you need a space between the command, printf, and its arguments (the quoted string you want to print). So while this fails:
$ printf'Hello world\n'
bash: ...
1
vote
show which of a list of filenames do not exist in a given list of directories
Leaving aside the consideration that a file MIGHT be in the wrong directory, and assuming you are starting with a list of JUST filenames/not paths, then the most efficient solution would be to get a ...
1
vote
How to write an alias or bash script that renames a single file using the same syntax as the `ren` command of Windows?
Bash brace expansion can be used:
To rename path/to/foo.txt to path/to/bar.txt we can generate these two paths from their common parts like this:
$ mv path/to/{foo,bar}.txt
Brace expansion doesn't ...
1
vote
Accepted
How to write an alias or bash script that renames a single file using the same syntax as the `ren` command of Windows?
I'm not particularly familiar with REN but it looks like the directory path provided in the first argument is where the renamed file should still end up.
The native solution could be something like ...
1
vote
show which of a list of filenames do not exist in a given list of directories
Assuming no newlines in file names, this is probably all you need:
readarray -t dirs < yourdirs
comm -23 <(sort -u yourfiles) <(find "${dirs[@]}" -type f -printf '%f\n' | sort -u)
...
1
vote
how to format a text file in bash with dots from right
You can print the numbers in thousands format and then change all commas to dots by tr command. Here is one way:
$ cat long_list | tr ' ' '\n' |
while read num; do
printf "%'d\n" &...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
scripting × 4495bash × 1542
shell-script × 1156
shell × 733
linux × 665
text-processing × 286
awk × 282
sed × 184
files × 176
ssh × 136
command-line × 136
grep × 135
cron × 104
find × 88
variable × 82
ubuntu × 75
terminal × 73
python × 73
rename × 68
perl × 66
ksh × 63
debian × 60
networking × 56
zsh × 54
regular-expression × 52