Sed is known as a Stream Editor in that it can carry out various filtering and/or transforming functions on standard input or on user specified files.

learn more… | top users | synonyms

2
votes
6answers
166 views

How can I extract text between a pair of the same character?

Input: blahŤfoobar1Ťblah Desired output: foobar1 I want to get the text between two "Ť" characters. Assume there will always be either 0 or 2 "Ť" characters, to make things easier. I tried the ...
3
votes
2answers
148 views

changing string with sed, where did it go?

$ cat test-paths.txt test/sub2/configuration.php test/sub3/configuration.php test/configuration.php test/sub1/configuration.php $ cat find-host-test #!/bin/bash for i in `cat test-paths.txt` do ...
1
vote
1answer
28 views

How to update the multiple files without changing file date?

I have replaced word 'merchant' to 'capital' in files founded in the current directory using following command: find * -type f -exec sed -i -e 's/merchant/capital/g' {} \; but above command will ...
1
vote
0answers
21 views

sed single qoutes, double qoutes, delimeters [duplicate]

I am confused a little bit. I would like to swap 2 directory in the apache2 config files with the sed program. APACHE_CONF=/etc/apache2/apache2.conf FULL_DIR=/home/$USER/new ...
3
votes
2answers
45 views

Automatically doubling the value of numbers in a string in multiple files

I'm trying to modify Java source code in numerous .java files that contain strings similar to this: private static final Height biomeHeight = new Height(0.1F, 0.2F); There are over 75 and I'd like ...
2
votes
2answers
37 views

How can I put a cluster lines in numeric order?

How can I convert this: -foo -bar 42 \ randomtext=00 "00" \ -randomtext=00 "00" \ -foo -bar 104 \ randomtext=00 "00" \ -foo -bar 1 \ -randomtext=00 "00" \ To this: ...
5
votes
8answers
507 views

How can I delete text that is NOT in quotes or parentheses?

Input: 19. "foo foo" (bar bar) (19) raboof "foo foo" raboof Expected output: "foo foo" (bar bar) (19) "foo foo" As you can see, I would like to keep the double quotes and parentheses. ...
3
votes
3answers
165 views

Regex Conversion

I'm wanting to make a command to edit /etc/default/grub and change the timeout from 10 to 2. Could anyone explain how to do this?
17
votes
5answers
373 views

How can I merge files on a line by line basis?

cat file1 foo ice two cat file2 bar cream hundred Desired output: foobar icecream twohundred I already have a solution involving a for loop with sed using the line number of the files, but in ...
4
votes
4answers
203 views

How can I extract text between parentheses containing a specific word?

How can I convert this: foo (blah) (bar 80) foo (cats) (blat 92) To this: foo bar 80 foo blat 92 I would like to keep all the text that is NOT in parentheses. I only want to extract text ...
6
votes
5answers
290 views

How can I edit a range of text between 2 symbols? awk, sed, regex

Using the "*" symbol, (doesn't have to be that one, any special character will do in order to indicate), how can I edit the text from this: *berry straw rasp blue boysen * blahblah blahblah blahblah ...
1
vote
1answer
23 views

What'd be a good SEd trick to list the properties of all X input devices?

A list of X input devices is returned using the command xinput --list and the properties of an input device are listed using a command of the form xinput --list-props "device name". How could SEd be ...
0
votes
2answers
21 views

how to use of sed command to search string with “/” character in it and replace with some other string?

I have run the command: sed 's/http:\/\//www/' filename In output,this command didn't replace "http://" with "www" why? and how to change delimiter in sed command?
10
votes
2answers
1k views

What does this 'apt-get remove' instruction do?

What does the following code do? I found it on internet so I copied it and pasted it into terminal but when I installed a new kernel it only detects the old one. sudo apt-get remove --purge $(dpkg ...
1
vote
2answers
63 views

Running a command in screen daemon mode

I am trying to run a command in screen mode using the command screen -dmS screen_name sed -i 's/a/b/'g some-file.txt Nothing happens. When I put the same command in a script and run the command: ...
1
vote
3answers
62 views

Edit text iteratively within a file using commands

I am a new Ubuntu user. Please help me in solving the following problem: My input text file is -0.716425 -12.8939 -3.3341 -7.38497 -2.62709 3.00437 -6.69861 -13.8853 -5.81095 -7.37465 ...
2
votes
1answer
44 views

sed to execute a command as replacement with substitution pattern as argument

I am trying to replace time in a log file by: cat mlog.log | sed -e "s/^[0-9\.]*/\$(date -d @&)/" Why it always first execute $(date -d $&) but not doing replacement at first and then ...
4
votes
3answers
120 views

Reverse sed's/regexes' pattern-matching priority order

Consider this command: echo "string.with.dots" | sed 's/\(.*\)\.\(.*\)/\1\n\2/' (Matches into a first capturing group any character until the last . and into a second capturing group any character ...
3
votes
4answers
256 views

What is a practical way to list every character used in a file (Bash) (Regex)

How can I turn this: Johnny's penguin, (Tuxie), likes the following foods: French fries, and beef. To this: abcdefghiklnoprstuwFJT',():. (These are the total characters used in the input) ...
1
vote
1answer
47 views

How to filter out links from html using grep or sed?

I am trying to filter the links related to the src attribute from the html of a web page. I used curl to get the html and below sed command to filter the url links. curl -s http://www.example.com/ ...
0
votes
0answers
34 views

sed error Bash script

So here's the deal I'm trying to do some auto editing of a file with sed in a bash script. Here's my code: systemdate=$(date) sudo mkdir "/tmp/autoupdate" sudo echo "$systemdate" > ...
3
votes
4answers
82 views

Replace string with multiline file content

I need to replace string SALT in a file with content of another file. Problem is that the input file has multilines. I tried something like this in my bash script: SALT=`cat salt.txt`; sed ...
3
votes
4answers
79 views

Find and replacement of the numerical part of a particular string with increased value using terminal command [duplicate]

The inputfile is, test00.dat test07.dat test03.dat aram22.dat test09.dat aram09.dat test13.dat I need the output file as test01.dat test08.dat test04.dat aram22.dat test10.dat aram09.dat ...
3
votes
3answers
203 views

How to label occurences of text?

I would like to convert blue blue red green to: color.1=blue color.2=blue color.3=red color.4=green Any leads on how to tackle this? sed, awk, etc.?
0
votes
2answers
48 views

How to highlight second vowel from every word in a file?

I am trying to highlight every second vowel in a word to the colour red. What am I doing wrong? cat room.txt | sed 's:[AEIOU]:$(printf "${\e[1;30m}&${\e[0m}"):i2' Ps. Sorry for making it ...
2
votes
3answers
94 views

How do I extract a single attribute from an XML file?

I'm not really familiar with regex, sed, etc. and a bit lazy to figure it out right this moment, so how do I extract this line: <yweather:astronomy sunrise="6:50 am" sunset="7:06 pm"/> Let me ...
3
votes
3answers
70 views

Move pattern to beginning of line

I am trying to reformat a log file such that date and time appear at the beginning of the line. My logs look like this: blah, blah, blah, Friday, Mar 13,2015 16:59:42 yadi, yadi, yada, Friday, Mar ...
1
vote
2answers
97 views

How can I add a backslash before all spaces of a file?

How can I replace a character with a space, preferably by using tr or sed commands? So I want this to happen in my script: #!/bin/bash line="hello bye" echo $line | tr ' ' "\\\ " This is supposed ...
5
votes
2answers
420 views

Use sed on a string variable rather than a file

I have been told it was possible, but without a single working example, that sed can read from a string variable without need for an input file. I have yet to get it to work. For general safety, I’m ...
2
votes
4answers
241 views

count the number of unique values based on two columns in a spreadsheet

I need to count the number of unique values based on two columns in a spreadsheet. Suppose the file looks like this, ordered by name, surname, company: joe allen ibm joe smith ibm joe allen google ...
0
votes
1answer
140 views

unterminated `s' command — running sed from a .sh script, to replace a string that includes a “=”

I am really struggling with a very silly but complex type of issue while running sed from a .sh script, to replace a string that includes a =. My command, sed -i 's/^host=.*/host=myhost1/' ...
2
votes
3answers
138 views

Remove all text before last space in text file from CLI

I want to remove everything before the last space in a text file from the CLI Example text: 2015-03-02 21:34:15 20480 dump-2015-03-02-21-34.tar The string that should remain is ...
1
vote
2answers
33 views

using sed to remove equals sign from a file

I am trying to use sed to remove the equals signs from this file and pipe it to a new file: I am a file to be edited. A unique file with my own words. T=h=e=r=e a=r=e i=s=s=u=e=s w=i=t=h t=h=i=s ...
0
votes
1answer
55 views

How to find and replace a particular string by increasing its numerical part? [duplicate]

My input file is, ami41 ami56 ami23 ami67 ami45 ami34 ami88 jama66 tumi234 bichi23455 susami345 Using a single command line I need the output as, ami42 ami57 ami24 ami68 ami46 ami35 ami89 jama66 ...
2
votes
4answers
120 views

Search and Replace from terminal, but with confirmation

In many text editors, you can do a search and replace and be given the option to inspect each found case. I'd like to be able to do something similar to this at the command line in ubuntu. I know ...
3
votes
3answers
251 views

How to find and replace a string by increasing its numerical part?

My input file is, ami21 ami65 ami67 ami66 ami88 ami76 ami29 ami55 ami54 ami32 Using a single command line I need the output as, ami22 ami66 ami68 ami67 ami89 ami77 ami30 ami56 ami55 ami33 I ...
1
vote
2answers
104 views

bash sorting multiple duplicate strings in a file

I have file like below: Personname:Mark Hobby:chess Hobby:tennis Personname:Tom Hobby:swimming Hobby:badminton Hobby:boxing Hobby:music Personname:Nick Hobby:swimming Personname:fabio Hobby:swimming ...
1
vote
1answer
82 views

How to replace word occurrence in ranges specified using sed command?

str="I want to abc replace a word abc in a sentence abc of file abc by giving abc specifying a abc multiple abc range to abc the sed abc command abc." The above sting str has word "abc" 10 times ...
2
votes
2answers
121 views

bash text colon values to html table

i had a big file with more than 10000 recordslike below, this need to be converted to html table i tried various ways with converting into csv and then to html etc.., not able to get the desired ...
0
votes
2answers
176 views

sed : difference between “ sed 's/\-.*// ” & “ sed '/\-/s/\-.*//gw ”

I am learning few simple sed commands and I have gone through few practices. Command #1 sed 's/\-.*//gw witout' tgs.txt Command #2 sed '/\-/s/\-.*//gw with' tgs.txt Output #1 $ cat with 2. ...
1
vote
1answer
47 views

Color the regular expression in same file

I have a big file and need to look over certain patterns. and also look for another patterns based on first pattern and thus this requires to color the lines which matches the search in the same file. ...
0
votes
1answer
50 views

Match Pattern and write following value as variable

I'm trying to match a pattern and then pull the following information to create a file using that variable. Example (my data may look like either of the 2 examples) "headers": { ...
1
vote
2answers
151 views

replace only the first and only the last match using 'sed'

I want to replace, and old string with a new one. This is what I used sed -i "0,|$old|{s|$old|$new|g}" file but it gives me error: sed: -e expression #1, char 3: unexpected `,' How to change it? ...
1
vote
1answer
54 views

What am I doing wrong with Sed

My input: sed -i 's/if ($.browser.msie)/if ($.browser={ msie: ( navigator.appName == 'Microsoft Internet Explorer') ? true : false })/g' file.js I have tried putting the search and the replace ...
0
votes
1answer
265 views

Is it possible to use variable in sed command in unix bash script [duplicate]

I trying to solve following problem. With great helps of others here, I can write and understand simple do loop in bash scripting. Now I try to do this: In "mein_directory" directory I need ...
0
votes
2answers
306 views

How to use sed to find the strings between 2 patterns?

I have file content like this: aaa accounting exec ... aaa accounting exec ... aaa accounting commands .. aaa accounting commands .. aaa accounting commands .. aaa accounting commands .. aaa ...
3
votes
4answers
367 views

How to select and print IP address from a set of strings?

I have a sentence whic contains an IP address. For example, This sentence contains an ip number 1.2.3.4 and port number 50, i want to print the IP address only. From the above sentence, I want to ...
0
votes
1answer
36 views

How to get indirect access on a file through script in linux

I have one file text1, on this only one user(user1) has read,write,execute permissions, rest of the world(user2) has read and execute permissions. I thought of having one script which changes the ...
0
votes
2answers
73 views

Insert text into file

I'm trying to insert some text into a file on a specific line which I have managed to do with sed the below being inserted into line 34 of the txt file. sed -i "34i some text" name_of_file.txt The ...
3
votes
6answers
777 views

rename multiple files with delimiters

How could I rename multiple files like, IonXpress_049.T11014.R_2014_11_13_11_26_35_user_PR2-41-Pooling0026_3140_13112014.bam ...