command line - creating a customized stat file out of files a current directory - Ask Ubuntu


i have files these:

$ cat a9e27.txt person,42% person,60% $ cat ffn2eg6.txt train,85% $ cat sbhfgkv.txt   person,85% person,73% chair,44% person,57% $ cat a8evamk.txt 

etc etc of txt files empty. how can create file this

1,a9e27.txt,person,42%,person,60% 2,ffn2eg6.txt,train,85% 3,sbhfgkv.txt,person,85%,person,73%,chair,44%,person,57% 4,a8evamk.txt 5, etc etc  

where 1 shows file number when sort file names alphabetically ls -1 | sort , a9e27.txt file name, , each line of file contents comes in front of separated comma

update: schrodingersscat's answer ubuntu irc correct on stdout:

$ in * ; echo -n "$i"; cat "$i" | sed ':a;$!{n;s/\n/, /;ba;}' ; done 5co16.txta9e27.txtperson,42%, person,60% ffn2eg6.txttrain,85% kkc4e.txtsbhfgkv.txtperson,85%, person,73%, chair,44%, person,57% 

gives correct answer how can save result shown on stdout file correctly?

kerframil bash irc:

$  i=1; f in *; [[ -f $f ]] || continue; data=$(tr '\n' ',' < "$f"); printf '%s,%s,%s\n' "$((i++))" "$f" "${data%,}"; done > ../../in-your-file-correctly.txt 

notes:

/join #bash  

Comments

Popular posts from this blog

download - Firefox cannot save files (most of the time), how to solve? - Super User

windows - "-2146893807 NTE_NOT_FOUND" when repair certificate store - Super User