I tried different solutions given in various linux portals but no luck..
The directory consists of files with no-extension.
Each file has only one line. I need to add each filename to the top of each file so eventually each file will have two rows.
Filenames have spaces between words and some files have multiple spaces at the end of their names.
At first I tried this one:
while read F ; do
grep sed -i '1i $F' $F > $F.txt
done
Also below one is not working:
for filename in $(ls $*)
do
sed "1s/^/${filename} \n/" ${filename} > $filename.txt
echo Done ${filename}
done
sleep 2
for FILE in `ls *` is a dangerous use of backticks and pointless besides, don't do that. * does not need ls or any other external command's help to work.
You can do this with a subshell, which first prints the file name, then reads out the file contents, with the entire subshell's output dumped into "$FILE".txt
for FILE in *
do
( echo "$FILE" ; cat "$FILE" ) < "$FILE" > "$FILE".txt
done
awk: cannot open #EXTINF:0,DE: (No such file or directory)
mv: target �CY� is not a directory
awk: cannot open #EXTINF:0,DE: (No such file or directory)
mv: target �.txt� is not a directory
awk: cannot open #EXTINF:0,DE: (No such file or directory)
mv: target �.txt� is not a directory