Skip to main content
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 ("...
aviro's user avatar
  • 5,922
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 ...
phuclv's user avatar
  • 2,201
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 ...
Ed Morton's user avatar
  • 32.4k
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)"} ) ...
Stéphane Chazelas's user avatar
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 ...
Ljm Dullaart's user avatar
  • 4,863
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/(.....
wobtax's user avatar
  • 318
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 ...
GammaZoid's user avatar
  • 149
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 ...
steeldriver's user avatar
  • 81.9k
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 ...
glenn jackman's user avatar
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 ...
Jim L.'s user avatar
  • 8,192
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: ...
terdon's user avatar
  • 245k
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 ...
symcbean's user avatar
  • 5,821
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 ...
Kaz's user avatar
  • 8,585
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 ...
Chris Davies's user avatar
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) ...
Ed Morton's user avatar
  • 32.4k
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" &...
user167612's user avatar
  • 1,700

Only top scored, non community-wiki answers of a minimum length are eligible