Search This Blog

sed: delete matching lines

sed -i.bak '/pattern/d' input.txt

Shell scripting: remove .DS_Store and ._* files recursively on Linux or Mac

find . -name ".DS_Store" -print0 | xargs -0 rm -rf
find . -name "._*" -print0 | xargs -0 rm -rf
find . -name ".DS_Store" -delete
find . -name "._*" -delete
find . \( -name '.DS_Store' -or -name '._*' \) -delete

Shell scripting: Removing repeating empty lines

cat -s 1.txt > 1.txt; mv 1.txt.tmp 1.txt

Shell scripting: enclose all lines with quotes

  • Using awk:
    awk '{print "\""$0"\""}' input.txt
    
    or if ignore empty lines:
    awk 'NF {print "\""$0"\""}' input.txt
    
  • Or using sed:
    sed -i.bak 's/^/"/; s/$/"/' input.txt
    
    or if ignore empty lines:
    sed -i.bak 's/^..*$/"&"/' input.txt
    

Shell Scripting: delete blank lines from a text file using sed

Delete empty lines using sed:
sed -i.bak '/^\s*$/d' 1.txt