0
votes
1answer
34 views

Want to replace the words with space in multiple files using SED commmand [on hold]

Want to replace the words with space in multiple files using SED commmand I have a word as 'Danny' with single quotes in many of my files in multiple directories which I want to change to 'Danny ...
2
votes
3answers
72 views

Regex not matching

why this does not match..? sed -e '/--Updated?[[:space:]]+Date/d' inputfile this..: --Updated Date: 2013-11-06 15:32:13 d? is because sometimes I have Update Date, and sometimes Updated Date. ...
1
vote
2answers
37 views

How can I append multiple extensions to a string with sed?

I want to create a script that will let me download images from entire subreddits at once, but I'm currently stuck on just getting the links right (one problem at a time! ^^). Anyway, since I can't ...
2
votes
2answers
68 views

Regex `/pattern/g` and ed `:g/pattern/`: which came first, and why `g`?

The g option (e.g. s/pattern/replacement/g) for many tools that use regex-style pattern matching and the :g command in ed/ex/vi/vim have pretty similar usage and meaning: match the given regex ...
4
votes
4answers
142 views

Print line after nth occurrence of a match

I am looking to display the line 4598 in the following file. Effectively I want to display the line AFTER the nth occurrence of a match. In this case, the line after the 3rd occurrence of <Car>. ...
2
votes
1answer
69 views

Counting consecutive repetitions of a specific character (e.g. ,)

Say I have a file with lines like the two following: foo,bar,,baz,xy foo,,bar,baz,xy,, I would like to count how many times I have ,, (two consecutive commas surrounded by any other character) in ...
1
vote
1answer
43 views

Why isn't sed using the extended regex mode by default?

I am using sed. I was using a regex that was correct as far as I could see but sed did not do anything. Turns out that I was using \s+ which sed can not understand (?) and when I switched to [ ]+ it ...
2
votes
2answers
48 views

Why don't I need to escape a character class in sed but I need to escape the rest?

I am confused with sed. I had a file with the following contents: [ 2014/02/10 14:45:15 | INFO ] Saving data for customer: 273667 [ 2014/02/10 14:45:15 | INFO ] Saving data for customer: ...
2
votes
2answers
93 views

SED change only start of line and preserve end of line

Basically I have a situation where I frequently need to modify my hosts file to access different servers at my workplace. In an attempt to automate the process. I've been trying to use sed to make the ...
1
vote
1answer
77 views

How to get the JSON STRING from the given string

I have a string given below. I just need to get the first accountHeader (bolded) JSON string, I tried everything.. It didn't work. Can you help me to get the data? <START ...
0
votes
1answer
37 views

All occurrences of a regex get removed without using the “global” modifier

I have the following text in the file sentence.txt Linux refers to the family of Unix-like computer operating systems that use the Linux kernel. Linux can be installed on a wide variety of ...
5
votes
6answers
393 views

Replace a character except last x occurences

I have a file that has a bunch of hostnames correlated with IPs that looks like this: x-cluster-front-1 192.168.1.2 x-cluster-front-2 192.158.1.10 y-cluster-back-1 10.1.11.99 y-cluster-back-2 ...
4
votes
2answers
61 views

Why sed prints first string from file even if it's failed to find matching groups

I'm trying to write sed expression which will extract matching groups from file. E.g. I have .cue sheet and I want to extract it's genre tag. It has following format: $ cat file.cue | grep GENRE REM ...
1
vote
1answer
82 views

Parsing csv with sed and perl one-liner?

I have a web server which stores configurations to PostgreSQL, and I plan to retrieve information from a certain table and then later parse it into csv format. PAYLOAD <?xml version="1.0" ...
0
votes
2answers
184 views

bash script, printing multiple lines that matching to a specific patern

I have a log file and I'm making a script to do some actions. An action is to print a specific area of the log. Every block at the log starts with a specific time stamp and inside the block may have ...
1
vote
2answers
89 views

Ensure /etc/export contains rule using bash

What's a working example of modifying /etc/export using bash? Example: I want to ensure the following rule is present and valid: /export/home 2400:123::/32(rw,no_root_squash) And it should: Add ...
1
vote
2answers
139 views

What does this regex mean?

I was working on the conversion of Unix newline to Windows newline. I tried to unix2dos but it gave me some binary error, so I looked it up and stumbled upon this regex sed 's/$'"/`echo \\\r`/" ...
3
votes
3answers
158 views

sed - how to (not) match unmatched brackets

How can I do my operation only on lines that close their brackets? For example I want to change ".is" lines and add a bracket but not for lines with unclosed brackets. so these are changed ...
0
votes
2answers
711 views

sed - how to exclude multiple patterns in the match

I have currently a set of seds that's working well except for one thing. The particular expression I'm having an issue with is: sed -i '/[^}.to]\.to[[:space:]]/ s/\(\S\)/expect(\1/' ...
3
votes
1answer
466 views

Get all regex matches between two patterns and print them to file

I've got a file with a bunch of long lines. I'd like to grab every group between two patterns and print them to a new file, one match per line. I could manage to do this with Python, but I'd prefer ...
1
vote
1answer
43 views

How to match a literal '*' with sed?

I have this line in my file called test.php 'dbs_password' => 'a8b*cyP0', and want to replace into: 'dbs_password' => 'password-here', So I use this sed command with syntax: $ sed -e ...
1
vote
3answers
54 views

Stuck in separating chars into strings in my approach. Found a working approach but can not understand it

I am trying to figure out how to break a string to be on character per line. I.e ahebhaaa to be: a h e b h a a a I tried: $ echo ahebhaaa | sed 's/\(.\)\(.\)/\1\n\2/g' I.e. my ...
4
votes
2answers
153 views

Why do I need to escape regex characters in sed to be interpreted as regex characters?

It seems e.g. cat sed_data.txt | sed 's/\b[0-9]\{3\}\b/NUMBER/g' that I must escape characters to form a regular expression. In this case I had to escape braces in order to be interpreted as a number ...
1
vote
2answers
209 views

sed : Ignore line starting whitespace for match

I want to replace the default listening port of httpd to 9090. I can edit the line in httpd.conf file using below sed -i "/^Listen/c\Listen 9090" /etc/httpd/conf/httpd.conf But the line Listen 80 ...
1
vote
2answers
111 views

Remove 2 and 3 newlines in a text file but not 1

I'm developing on a max osx 10.8 and have no preferences to which tool to use probably sed but it doesn't matter. Update after comment: The input file uses windows new lines if that's complicates ...
4
votes
1answer
179 views

grep: display filename once, then display context with line numbers

Our source code has error codes scattered throughout. Finding them is easy with grep, but I'd like a bash function find_code that I can execute (eg. find_code ####) which will provide output along ...
2
votes
3answers
83 views

Pulling out keywords using standard command line utilities?

As an example, this is the pronunciation of "when" according to Wiktionary. enPR, IPA and X-SAMPA are different schemes for showing pronunciations. when:* {{a|US}} {{enPR|wĕn|hwĕn}}, ...
5
votes
1answer
152 views

Execute a command within 'sed'

I have a list of random memory addresses saved in a text file, and I need to sed them out, decode them, and save them back to my file. However, the decoding operation I'm trying to perform is handled ...
3
votes
4answers
195 views

Replace all occurences of \ except \N

I have a file like this: 1,2,subjects,\mat\hs,unix\,\Nato,\N,123,\N I want to replace all occurences of \ with #, except for \N, such that the output looks like this: ...
1
vote
2answers
96 views

Backreferencing with sed

I have a database containing a list of unsigned longs representing a bunch of memory addresses followed by an offset within two brackets (e.g. Mem[offset], 0x2322AD4[3]), and some other data. What I ...
1
vote
2answers
109 views

Tell a regex expression to skip the beginning of a line before matching

If I had a string like 45mb ./aaaa/bbbb/cccc/dddd and I use a regex like [^\/]*\/ it will match 45mb ./aaaa/bbbb/cccc/ I only want it to match ./aaaa/bbbb/cccc/ but I can't figure out how to do ...
1
vote
1answer
73 views

What are the commands that you can use in the beginning of a sed command?

I initially learned to do sed search and replace like so: sed -e 's/<stuff>/<replacement>/' However I recently learned that these will do something different based on what command ...
0
votes
3answers
100 views

Removing second colon

Trying to create a simple script that lists mass mailing by the queue number that appears in /var/log/maillog. I'm starting off with this: [root@ditirdlns01 ~]# lsMails(){ grep -i ...
2
votes
3answers
2k views

extract part of string using sed

ls lib/oracle-11.2.0.3.0.txt | sed 's/lib.\([oracle.*]\)\.txt/\1/' It is giving the whole string instead of just oracle part until .txt What am I doing wrong? I can do it using awk as follows, but, ...
0
votes
4answers
1k views

Extract substring using regular expression on a Unix file

I have file with below contents . /ABC/RTE/AD_900_VOP_123/OPP /ABC/RTE/TRE/AD_900_VOP_145/BBB /ABC/RTE/AN_900_VFP_124/FBF /ABC/RTE/HD_900_FOP_153/WEW /ABD/RDV/AD_900_VOP_123/OPP ...
3
votes
5answers
3k views

Using sed to find and replace complex string (preferrably with regex)

I have a file with the following contents: <username><![CDATA[name]]></username> <password><![CDATA[password]]></password> ...
4
votes
3answers
653 views

Remove string from a particular field using awk/sed

I have a file (>80,000 lines) that looks likes this: chr1 GTF2GFF chromosome 1 249213345 . . . ID=chr1;Name=chr1 chr1 GTF2GFF gene 11874 14408 . + . ...
1
vote
2answers
55 views

Trimming one part if equal to another part?

I use an e-mail quote attribution string like this: On dd mmm yyyy hh:mm +hhmm, from info@example.org (Example Dot Org): where info@example.org is the sender's e-mail address and Example Dot Org is ...
0
votes
1answer
60 views

Comment the if statement and the matching endif keyword

In vim, I can find the matching if statement and prepend the appropriate comment symbol. (e.g. %s/.alarm./#\0/g), but then I am left with dangling endifs that I have to find manually. I could simplify ...
3
votes
3answers
952 views

Delete XML node containing certain element

I want to remove all Placemarks from a KML file that contain the element <tessellate>. The following block should be wholly removed: <Placemark> ...
1
vote
2answers
164 views

Regex and piped commands with sed

I'm finding really hard to use sed command, plus I can't seem to find well written tutorials. Let me say that I worked with regular expression in other languages (Python, JavaScript, Java), so that ...
2
votes
3answers
251 views

awk, sed, grep, perl… which to print out in this case?

I have this syntax in a file (http response times from analog): <thead><tr><th class="x">seconds</th><th class="R">reqs</th><th ...
2
votes
2answers
174 views

changing pattern by removing spaces?

file : hi hello,new york, , ,brazil site ,brazil january,month is feb , , ,indiana jones task: delete all horizontal space (spaces and tab) between any two comas (like , ,) if ...
4
votes
2answers
266 views

Why does this add spaces? echo “x ax” | sed 's/x\s*/x /'

I want to find a x, and replace the 0 or more following spaces (\s*) with just a single space. echo "x ax" | sed 's/x\s*/x /' For some reason, instead of replacing the spaces with the single space, ...
2
votes
2answers
816 views

extract last match from logfile till end

Using sed, grep, awk, or ruby, what's a simple way to find the last match of a string in a larger log file, and send every line following it (inclusive) to another file? Example: grep -A222 ...
1
vote
2answers
283 views

How can I find matches with sed (or similar) for configuration parameters?

I'm pretty good at using php's preg_match (and similar) commands, and I'm also pretty good with regular expressions, but I don't do very well with sed. I have two shell scripts I'm working on and I'd ...
3
votes
2answers
2k views

Removing Color Codes From Output [duplicate]

Possible Duplicate: Removing control chars (including console codes / colours) from script output I'm working on a script to work alongside a program that I'm writing. What i'm trying to do ...
2
votes
1answer
2k views

sed special character replace not working in shell script

I want to write a script 'test.sh' that will take a user's input and replace all special characters with a '\' + the character. My script: #!/bin/bash echo 'input='"$1" arg=`echo "$1" | sed ...
0
votes
1answer
343 views

Remove a block of lines between two patterns [duplicate]

Possible Duplicate: Show only text between 2 matching pattern In a bash script using sed how can I remove a block of lines beginning with -pattern a- and ending with -pattern b- where the ...
1
vote
4answers
536 views

Replace text between brackets

I'm using awk '{ gsub(/BAR|WIBBLE/, "FOO"); print }' to replace text in data like: SOMETHING [BAR, WIBBLE] SOMETHING [BAR] This gives the desired result of: SOMETHING [FOO, FOO] SOMETHING [FOO] ...