sed command

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?

{ 1 comment }

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?

{ 1 comment }

Linux / UNIX: Sed Replace Newline

by Vivek Gite on January 6, 2009 · 2 comments

How do I replace newline (\n) with sed under UNIX / Linux operating systems?

{ 2 comments }

Most Linux / UNIX configuration files are documented using comments, but some time I just need to see line of configuration text in a file. How can I view just the uncommented configuration file directives from squid.conf or httpd.conf file?

{ 6 comments }

Q. How do I find the text between the strings FOO and BAR inclusive using sed command line option?

{ 25 comments }

sed Case Insensitive Search Matching

by Vivek Gite on March 14, 2008 · 2 comments

Q. How do I perform a case-insensitive search using sed under UNIX / Linux? I’d like to match all combination of word – foo, FOO, FoO and so on while replacing or performing other operations.

{ 2 comments }