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 ...
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}' ...
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....
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 ...
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/...
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 ? ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
sed × 6740awk × 2679
text-processing × 2221
grep × 892
bash × 840
regular-expression × 810
shell-script × 774
linux × 737
perl × 401
shell × 386
replace × 214
scripting × 176
command-line × 165
csv × 152
xml × 125
find × 121
string × 116
text-formatting × 111
files × 108
cut × 99
macos × 88
quoting × 83
tr × 72
json × 69
variable × 62