≡ Menu

sed command

sed Tip: Delete All Blank White Spaces

I have a text file as follows:


How can I delete all leading and/or trailing blank spaces, tab from each line using sed command?
[click to continue…]

Linux: Dell Laptop Fan Control And Get CPU Temperature

I have installed Debian or Ubuntu Linux on Dell Inspiron / Latitude / Precision / Vostro laptop. How do I see the current CPU temperature? How do I control and see fan status on Dell laptop?
[click to continue…]

Linux / Unix: Shell Remove Empty Lines

I am a new Linux user. I have text files with lots of empty lines. How do I delete all empty lines under Linux or Unix operating systems?
[click to continue…]

Unix / Linux: Show First 10 or 20 Lines Of a File

I have a directory with many files. I am trying to write a shell script that will only show first 10 or 20 lines of a file. How do I display first 10 or 20 lines of a file on Linux or Unix-like systems?
[click to continue…]

Linux / Unix: Display First Line of a File

How do I display first line of a text file called foo.txt on Linux or Unix-like operating systems?
[click to continue…]

Bash Shell: Remove (Trim) White Spaces From String / Variable

I have a bash variable as follows:

output="$(awk -F',' '/Name/ {print $9}' input.file)"

How do trim leading and trailing whitespace from bash variable called $output? How do I trim trailing whitespace from $output?
[click to continue…]

Sed: Find and Replace The Whole Line [ Regex ]

I have a line as follows in squid.conf file. My sever is hosted in a cloud:

acl verizonfios src

My ISP will force an IP address change every week or two. I would like to replace them with a new IP

acl verizonfios src

How do I replace the line starting with "acl verizonfios" with new IP address using sed and ssh?
[click to continue…]

Linux / Unix: sed Command Print Only Matching Lines

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?
[click to continue…]

Linux / Unix sed: Delete Word From File / Input

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?
[click to continue…]

HowTo: grep Text Between Two Words in Unix / Linux

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

 <title>Statistics for ABC LTD - January 2007 - Rang IDXYZZAZZZZ</title>
<body BGCOLOR="#E8E8E8" TEXT="#000000" LINK="#0000FF" VLINK="#FF0000">
<h2>Statistics for ABC LTF</h2>
Summary Period: January 2007<br />
Generated 01-Feb-2007 06:40 CET<br />
<hr />
<font SIZE="-1"></font></p></center><pre>
my data 1
my data 2
my data 3
my data 10000
my data N times

Generated by MyAppDbStatsWriter (UNIX) version 1.9b2

How do I extract text between two words (<PRE> and </PRE>) in unix or linux using grep command?
[click to continue…]