Questions tagged [sed]

Sed stands for Stream EDitor - one of the basic tools in the POSIX environment. It processes one or more files according to an editing script and writes the results to standard output. Created in Bell Labs, it has been around since mid-70s.

271 questions
106
votes
11 answers

How to display certain lines from a text file in Linux?

I guess everyone knows the useful Linux cmd line utilities head and tail. head allows you to print the first X lines of a file, tail does the same but prints the end of the file. What is a good command to print the middle of a file? something like…
Boaz
  • 2,159
  • 5
  • 19
  • 15
51
votes
8 answers

bash/sed/awk/etc remove every other newline

a bash commands outputs this: Runtime Name: vmhba2:C0:T3:L14 Group State: active Runtime Name: vmhba3:C0:T0:L14 Group State: active unoptimized Runtime Name: vmhba2:C0:T1:L14 Group State: active unoptimized Runtime Name: vmhba3:C0:T3:L14 Group…
carillonator
  • 805
  • 3
  • 12
  • 22
39
votes
6 answers

How to rename multiple files by replacing word in file name?

Replace ACDC to AC-DC For example we have these files ACDC - Rock N' Roll Ain't Noise Pollution.xxx ACDC - Rocker.xxx ACDC - Shoot To Thrill.xxx I want them to become: AC-DC - Rock N' Roll Ain't Noise Pollution.xxx AC-DC - Rocker.xxx AC-DC -…
holms
  • 1,464
  • 7
  • 20
  • 37
36
votes
5 answers

Using sed to remove both an opening and closing square bracket around a string

I'm running this command in a bash shell on Ubuntu 12.04.1 LTS. I'm attempting to remove both the [ and ] characters in one fell swoop, i.e. without having to pipe to sed a second time. I know square brackets have special meaning in a regex so I'm…
Xhantar
  • 1,002
  • 1
  • 8
  • 11
32
votes
8 answers

how to find out mac addresses of all machines on network

Is there some easy way to find out mac address of all machines on my network rather than doing an SSH into each and ifconfig | grep HWaddr if there are 300 machines on network I really need some easy solution.
Registered User
  • 1,453
  • 5
  • 18
  • 37
28
votes
4 answers

sed replace all tabs and spaces with a single space

I got a string like the following: test.de. 1547 IN SOA ns1.test.de. dnsmaster.test.de. 2012090701 900 1000 6000 600 now I want to replace all the tabs/spaces inbetween the records with just a single space so I can easily use…
Zulakis
  • 4,191
  • 14
  • 44
  • 75
20
votes
4 answers

Linux shell command to filter a text file by line length

I have a 30gb disk image of a borked partition (think dd if=/dev/sda1 of=diskimage) that I need to recover some text files from. Data carving tools like foremost only work on files with well defined headers, i.e. not plain text files, so I've fallen…
Li-aung Yip
  • 413
  • 1
  • 4
  • 9
18
votes
7 answers

How to parse and convert ini file into bash array variables?

I'm trying to convert an ini file into bash array variables. The sample ini is as below: [foobar] session=foo path=/some/path [barfoo] session=bar path=/some/path so these…
Flint
  • 631
  • 5
  • 10
  • 18
16
votes
3 answers

How to delete all characters in one line after "]" with sed?

How to delete all characters in one line after "]" with sed ? Im trying to grep some file using cat, awk. Now my oneliner returns me something like 121.122.121.111] other characters in logs from sendmail.... :) Now I want to delete all after "]"…
B14D3
  • 5,110
  • 13
  • 58
  • 82
15
votes
6 answers

How can I easily convert HTML special entities from a standard input stream in Linux?

CentOS Is there an easy way to convert HTML special entities from a data stream? I'm passing data to a bash script and sometimes that data includes special entities. For example: "test" & test $test ! test @ # $ % ^ & * I'm not sure why…
Mike B
  • 11,570
  • 42
  • 106
  • 165
15
votes
4 answers

read specified range of lines from a file

I have i file that contains 100000 line how i can get the lines from line# 5555 to line# 7777 under linux. Thanks for all.
ibrahim
12
votes
4 answers

SED replace across multiple lines

I am trying to find these three lines: and replace them with: When I try sudo sed -i 's: