One of the best command to rename all the files having same extensions. This is one line command. Say you have 100 files with same extension jpg and you want to convert all the jpg files to gif files so here is the below command to do it.
ls -d *.jpg | sed -e 's/.*/mv & &/' -e 's/jpg$/gif/' | sh
you just need to replace jpg instead of the extension you have and replace gif value with what extension you want to replace.
Hope this might be definitely helpful for you.
Showing posts with label sed. Show all posts
Showing posts with label sed. Show all posts
Thursday, September 10, 2009
Friday, August 14, 2009
use sed to find and replace a particular text
One of my colleague asked me how to find and replace a particular text in a remote shell where X Windows / any IDE is not available. I just googled for sometime and then I tried my self with only one hint to use the sed command. You will not believe I tried it for 5 times and I got the thing working at the 6 attempt, wow i felt so happy. Anyway back to the command, please use the below command to find and replace in any file.
sed -i "s/example/sample/g" *
The above command will find "example" text in all the files present in the current directory and replaces them with "sample" text. The text example / sample not only accepts exact words but regular expression is also possible.
Please feel free to ask me if you need any help regarding this.
sed -i "s/example/sample/g" *
The above command will find "example" text in all the files present in the current directory and replaces them with "sample" text. The text example / sample not only accepts exact words but regular expression is also possible.
Please feel free to ask me if you need any help regarding this.
Friday, March 13, 2009
use sed to fetch a part of the file.
Suppose say you have a very huge file which might be in GB(s) and you want only a part of the file to be seen then vi is not suitable to view that file. Instead use a sed which does this job very easily.
sed -n -e 'Start_line_number,End_line_number p' Filename
This will retrieve only those lines staring from "Start_line_number" and upto including "End_line_number"
This is best useful command to retrieve only a part of file which is very huge and big.
sed -n -e 'Start_line_number,End_line_number p' Filename
This will retrieve only those lines staring from "Start_line_number" and upto including "End_line_number"
This is best useful command to retrieve only a part of file which is very huge and big.
Subscribe to:
Posts (Atom)