≡ Menu

sed command

sed Find and Replace ASCII Control Codes / Nonprintable Characters

Q. How do I find and replace character codes ( control-codes or nonprintable characters ) such as ctrl+a using sed command under UNIX like operating systems?
[click to continue…]

Bash Shell: Replace a String With Another String In All Files Using sed and Perl -pie Options

How do I replace a string with another string in all files? For example, ~/foo directory has 100s of text file and I'd like to find out xyz string and replace with abc. I'd like to use sed or any other tool to replace all occurrence of the word.
[click to continue…]

Sed Delete Last Character

How do I delete a last character from input line under UNIX / Linux using sed tool? My sample scientific input data line is as follows and I'd like to get rid of last + character only:


How do I used sed to delete last + character?
[click to continue…]

Delete text or paragraph between two sections using sed

Q. How do I use sed for selective deletion of certain lines? I have text as follows in file:
Line 1
Line 2
Line 4

I would like to delete all lines between WORD1 and WORD2 to produce final output:
Line 1
Line 2

A. For selective deletion of certain lines sed is the best tool. To print all of file EXCEPT section between WORD1 and WORD2 (2 regular expressions), use
$ sed '/WORD1/,/WORD2/d' input.txt > output.txt

Shell script to remove Javascript code

Here is my small script that reads all *.html files and removes javascript (script download link).

# for loop read each file
for f in $FILES
# replace javascript
sed '/<script type="text\/javascript"/,/<\/script>/d' $INF > $OUTF
/bin/cp $OUTF $INF
/bin/rm -f $OUTF

Above shell script removes all occurrence of javascript.

Howto: Linux command line utilities for removing blank lines from text files

Q. I want to change the formatting of a file. I just wanted to remove all blank lines from text file. How do I achieve this task w/o spending much time?
[click to continue…]

sed: Remove All Except Digits (Numbers) From Input

How do I remove all (text, special characters, white spaces, tabs etc) from my text file (input) except numbers (digits) using sed command?
[click to continue…]

Bash Script Replace Empty Spaces String

How do I remove all spaces from string using shell scripts? I've var="This is a test", and I'd like to remove all spaces.
[click to continue…]