bash - Prepend basename to text files -
i'm trying insert basename of text file new line in same file entire directory of files (all different basenames). file "frog.txt" content:
asdf wef sdf ...becomes:
frog asdf wef sdf
you can try bash one-liner:
for file in "sample1.txt" "sample2.txt"; sed -i "1i${file%%.*}" "$file"; done this loop through each file name. ${file%%.*} remove extension $file. sed -i '1...' insert filename (without extension) first line.
Comments
Post a Comment