I have a file that should contain 200 characters in each line. I got a source file containing only 100 characters in each line. I need to add 100 extra spaces to each line. If there were a few spaces, we could use sed as:
sed 's/$/ /' filename > newfilename
Since it's 100 spaces, can someone tell me if it can be added to Unix?
WITH awk
awk
awk '{printf "%s%100s\n", $0, ""}' file.dat
$0 applies to the entire line.
$0
n ( m ), . :
$ cat file 1 12 123 1234 12345
10 .
$ awk '{printf "%-10s\n", $0}' file | cat -e 1 $ 12 $ 123 $ 1234 $ 12345 $
, 10 200 script. $ , , . cat -e, , .
$
cat -e
, , , - , , , say .
say
perl -nlE 'say $_," "x100' file
Perl:
perl -pe 's/$/" " x 100/e' file
... " (s) ($) (e) 100 ".
s
e
, , 200 , ( ), - :
perl -pe '$pad=200-length;s/$/" " x $pad/e'
83, 102 197 200 .
bash,
bash
while IFS= read -r line do printf "%s%100s\n" "$line" done < file > newfile
Test
, 3 ,
$ wc -c file 16 file $ wc -c newfile 316 newfile
spaces=$(echo {1..101} | tr -d 0-9) while read line do echo -e "${line}${spaces}\n" >> newfile done < file
printf awk:
printf
awk '{printf "%s%*.s\n", $0, 100, " "}' filename > newfile
printf 100 .
GNU awk - sprintf.
GNU awk
sprintf
awk 'BEGIN{s=sprintf("%-100s", "");}{print $0 s}' input-file > file-with-spaces
: -
$ cat input-file 1234jjj hdhyvb 1234jjj 6789mmm mddyss skjhude khora77 koemm sado666 nn1004 nn1004 457fffy $ wc -c input-file 92 input-file $ awk 'BEGIN{s=sprintf("%-100s", "");}{print $0 s}' input-file > file-with-spaces $ wc -c file-with-spaces 492 file-with-spaces
Bash, sed, readline, 100 (. manual for "Readline arguments" ).
:
sed 's/$/
100 . , readline, , , 100 , .. , , :
M-1 0 0 \040
, alt: Alt + 1 0 0 Space
100 ,
sed 's/$/ /' filename
.
This is useful for working in an interactive shell, but not very beautiful for scripts - use any of the other solutions for this.
Source: https://habr.com/ru/post/1663000/More articles:Как объединить данные в ранее существовавшую структуру JSON в R? - jsonBoost :: Regex Segfault (I think) - c ++Delete DOM element with AngularJS - domFirebase with older Google Play services - androidMapKit Memory Leaks (iOS 10) - iosЗапрос структуры Entity на только что добавленные, но не сохраненные значения - c#One data file, two applications, two dbConterxt - c #How to create a Redis Transaction in Go using the go-redis / redis package? - goCheck for free work - cWhy does scala map not implement unapply? - scalaAll Articles