sed command

I see many examples and man pages on how to do operations like search-and-replace using sed. But, I want to match a given string or a regular pattern expression and display on the screen. How do I print lines with matching pattern using sed command only under Unix like operating systems?

{ 0 comments }

I‘ve a file as follows:

This is a test.
One bang two three
Foo dang Bar
001 0xfg 0xA
002 0xA foo bar 0xfG
I'm done

How do I delete all “words” from the above file which ends with a particular letter (say ‘g’) in each line? The output should be as follows:

This is a test.
One two three
Foo Bar
001 0xA
002 0xA foo bar
I'm done

How do I delete regex-based word using sed or awk under Linux / Unix like operating systems?

{ 6 comments }

I got over 100s of HTML files in the following format:
….
…..

<PRE>
my data 1
my data 2
my data 3
my data 10000
my data N times
</PRE>
.....
..

How do I extract text between two words (<PRE> and </PRE>) in unix or linux using grep command?

{ 9 comments }

I‘m using the date +’%D_%T’ to store Unix system date and time in a shell variable called $_now:

_now=”$(date +’%D_%T’)”
echo $_now

Outputs:
01/20/12_16:10:42

I’d like to replace / and : with _. I’m aware of the following sed command:

sed ‘s/\//_/g
> s/:/_/g’ <<<"$_now"

Outputs:
01_20_12_16_14_09

How do I specify two pattern within the same sed command to replace | and : with _ so that I can get output as 01_20_12_16_10_42?

{ 3 comments }

I have a file called rsnapshot.conf. It has the words “ssh_args=-p 1222″. How do I match and remove (delete) the words “ssh_args=-p 1222″ from config file using sed command under Linux or Unix like operating systems?

{ 0 comments }

My script depends upon $1 to take certain actions:

file=”$1″
echo “|${file}|”

However, sometime there will leading while space which will result into:

|     output.txt|

How do I trim leading white space from one of my input variables?

{ 9 comments }

How can I remove the ^M or ^M (carriage Return / line feed ) from text file using sed under UNIX or Linux operating systems?

{ 13 comments }