≡ Menu

sed command

sed Tip: Delete All Blank White Spaces

I have a text file as follows:

   foo
   bar
  foobar 

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

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…]

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 1.2.3.4

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 4.5.6.7

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