5

script to change first line of files in directory

view full story
linux-howto

http://www.unix.com – I need a script to take the filename of every file in a directory and substitute that file name for whatever is on the first line of the file. There may or may not be anything on the line, but I want the line to be the same as the file name. Most of the script tools I have used are non-destructuve, so I'm not sure how to go about this. I guess I could write to a temp file, delete the original, and then rename the temp, but that seems rather crude. My understanding is this is what the sed c command is for (something like sed '1 c filename' file.txt), but I'm not sure of the usage and how I w (HowTos)