2022 Developer Survey is open! Take survey.

Hot answers tagged

2 votes
Accepted

How to use find and sed to replace certain sentences in files

You can do this in a two-step process, whereby in the first phase, using the TAB-delimited table file, we generate a set of grep & sed commands , and store them in a different hierarchy so that ...
user avatar
  • 5,343
2 votes
Accepted

Sed script to AWK

It seems that your task is what grep is doing. If you really don't want the colons, replace them with space using tr, assuming colons don't exist into filenames. grep -Eon '[0-9]{3}-[0-9]{6}-[0-9]{2}' ...
user avatar
  • 6,260
2 votes

Append a character at the beginning of next line matching the pattern throughtout the file

With awk: awk '{print} /^#EXTINF/ && getline {print "#" $0}' file Print any line and then test the pattern. If pattern matches, the getline call fetches the next line for processing....
user avatar
  • 6,260
2 votes
Accepted

Append a character at the beginning of next line matching the pattern throughtout the file

$ sed -e '/^#EXTINF/{n;s/^/#/;}' Test.txt #EXTM3U #EXTINF:100 #a.flac #EXTINF:20 #b.flac where n prints the pattern space (in this case, the line matching ^#EXTINF), then reads the next line of ...
user avatar
  • 72.2k
1 vote

Sed script to AWK

@thanasisp is right, grep is ideal for this job. With awk, you can write awk -v OFS=, ' match($0, /[0-9]{3}-[0-9]{6}-[0-9]{2}/) { print FILENAME, FNR, substr($0, RSTART, RLENGTH) } ' /mnt/c/...
user avatar
1 vote
Accepted

Not obtaining lazy evaluation using sed

Most versions of sed don't support perl style regular expressions (the only one I know of that does is "super sed", ssed, and that hasn't been updated since 2005), and don't support the ? ...
user avatar
  • 66.6k

Only top scored, non community-wiki answers of a minimum length are eligible