I have 8 files in a folder. If any of these files has 2 lines I need to remove the second line from that file. If a file has more than 2 lines then then I do not need to do anything to it.Can anyone help me with writing the shell script?
Delete line from files
shell;files;scripting
With find and sed:find -type f -exec sh -c '[[ $(sed -n $= $0) -eq 2 ]]' {} \; -exec sed -i '1!d' {} +Note: find should be tweaked with PATH and -maxdepth depending on the directory structure.