sed is a command-line stream editor for filtering and transforming text.

learn more… | top users | synonyms

1
vote
1answer
45 views

Replacing mysql settings with sed

I am creating a backup web server but I want the backup server to only have one root user. So after moving all the databases I need to replace all the mysqli_connect(...) lines in db.txt. I have ...
0
votes
2answers
52 views

Can sed save its output to a file?

> can do it. echo "text" > file tee can do it. echo "test" | tee file Can sed do it without using either of the above? Is it possible to save the output of a sed command to a file without ...
1
vote
1answer
22 views

How does this sed command works?

How does this sed line works : echo lred_6607: broken symbolic link to ./safaribooks/red_6607 | sed -e 's/^\|: *broken symbolic.*$/"/g' 1.There is no | character in the output of previous command. ...
1
vote
4answers
84 views

Impose character between repeated characters

Given a string of characters ,,a,,,b,,,, I want to impose the character - at the beginning, if no character is preceded comma, and between every comma that has no character. Meaning the result is -,-,...
1
vote
3answers
42 views

Unable to use a escape sequences in a variable in a sed command

I'm using sed to highlight a column in the output of a ps command, and it works fine if I hard code the color code. However, the color needs to be dynamic, so I tried moving it to a variable, and ...
2
votes
1answer
45 views

Highlight nth column of ps output

I'm trying to find the best way to highlight a specific column of some output. Specifically, I'm trying to highlight the 9th column (which is %cpu of the command: ps -eo pid,ppid,time,user,tty,%cpu,%...
1
vote
3answers
34 views

Text field with duplicate info

I have a tab-delimited data file with text fields, where some fields have duplicate information, semicolon delimited: 2000;2000 05/19/2016;05/19/2016 foo;foo How can I use sed to remove the ...
0
votes
1answer
56 views

Prepare update command using sed

I have a output file that contains 3 different column data- ['AARF'],SAMPLE12,2016-01-05 12:00:00-0500 ,529OFFST,2015-04-16 08:04:21-0400 "['EPROSP_IWS', '...
2
votes
4answers
362 views

How can I split a line into two lines if the length is greater than 7 using awk? [closed]

For example I just wanted to print something like this in the command line. Let say I have a file called file.txt. What is life? how are you? hi whatup this is more than And I want to print it ...
0
votes
2answers
58 views

How to determine what IP addresses are available in a hosts table?

I'm working on a script that will read from the /etc/hosts file and determine what IPs are available in the hosts file. The way the hosts file will look is as followed: 172.17.164.2 System1 172.17....
3
votes
2answers
31 views

Edit file based on existence of a string

I have an input file say file1 which appears as follows WRITE=2 START=1 SMEAR=0 MIN=6 MAX=100 My problem is to search for the string SMEAR and if the string exists replace the entire line with ...
-4
votes
1answer
35 views

How to change certain word in certain line in a file [duplicate]

i have a file in which i have to change a word and then save it by same name. for ex- for file "name"- my name is joe (original data) my name is roy (changed data) how to do it in best possible ...
0
votes
1answer
35 views

sed replace with value from an argument [duplicate]

Although this seems like a simple task, the sed call is not substituting the value that I send for IP. Instead, it is replacing localhost with "${IP}". substitute() { export IP=$1 echo $IP ...
0
votes
1answer
38 views

how to interpret “grep -Rl jdk1.7.0_80 . | xargs sed -i s,jdk17.0_80,weblogic”?

I have just installed Oracle weblogic on rhel server. Installation went successfully however the install guide given to me to run below command without explanation. I would like to know what I am ...
2
votes
4answers
76 views

Replacement of XML based on attribute content using sed

I've got to replace some attribute content in an XML tag, depending on a parameter $1. We've got in input, for example: <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="OO ...
0
votes
1answer
18 views

Log from a specific line to another specific line [duplicate]

I am doing a data monitoring and I am doing a cron job to get the data everyday. But I am receiving many junk data with my actual data that makes the file huge. For example my data is, eg.hh.jk.ll.mm ...
0
votes
0answers
26 views

Sed command for find and swap string [duplicate]

We are having the entry shown below in /etc/ldap.conf uri ldap://abccmnldap01.xyz.com ldap://pqrcmnldap01.xyz.com I want to swap abccmnldap01.xyz.com with pqrcmnldap01.xyz.com in ldap.conf with sed:...
1
vote
1answer
45 views

Replace one block of text with another block of text when replacement text is in a file

I have two files. The fist file is an existing C/C++ source file (*.cpp). The second is a text file (*.txt) and contains one function. The function is in both files, and it needs to be copied from the ...
-1
votes
1answer
36 views

Using sed to merge two lines [duplicate]

I'm trying to merge these two lines that appear periodically in a text file. travel_ by_night_and_day I have tried: sed '/_\nby/_by/s' input.txt > output.txt but, it doesn't do anything. Do ...
0
votes
1answer
25 views

sed - match on IP octet and remove line

I am in need of a solution, preferably sed, that can match on an IP octet that contains any number combination and remove the line. For example: My file: 192.168.100.12 192.168.200.12 10.10.20....
1
vote
3answers
105 views

add text on line before match

Trying to add text on the line before that it find the match (updateKey.sh) in this case, but won't get it to work. Here is my crontab file that the script adds the line to 0 06,18 * * * /home/server/...
0
votes
1answer
25 views

Linux red hat + replace PATH or word on scripts

Under folder: /var/userTN/applo folder I have around ~100 shell scripts that include the following PATH: GLOBAL_PATH=/export/pop/PLW5 I want to replace the PATH on all the scripts under folder: ...
0
votes
1answer
39 views

Bash add text on line script [closed]

Trying to get my script to work but it won't work. Here is my script #!/bin/bash a="* * * * * /home/server/scripts/check.sh" b="0 06,18 * * * /home/server/scripts/checks2.sh" sudo sed -i '28s/^/'$b'\...
0
votes
0answers
23 views

Preparing update command using sed

I have a sample input file- ,4.IM-H-506X,2016-01-01 11:07:27-0500 ['LOWERCASETEST7'],JASONTEST7,2015-04-19 00:00:00-0400 "['EPROSP_IWS', '648099_EPROSP_IWS']",4.NDR-IWS-EPRO,2015-04-16 08:...
1
vote
2answers
39 views

Is my interpretation of `sed -i.bak '/^x /d' “$SOME_FILE”` correct?

For some reason sed has always intimidated me, its syntax is a little odd I suppose. I want to make sure I understand what the following will do. sed -i.bak '/^x /d' "$SOME_FILE" This will first ...
1
vote
1answer
30 views

Parsing Data File's Lines by Delimiter Instead of EOL

I'm trying to parse a large text file (600MB) of raw data which I have no control on its format. The problem is that the end of line is not placed well: head -1 filename | wc -w Produces a count ...
1
vote
4answers
128 views

How to add a new text line at the first line of a file? [duplicate]

File: TABLE1 1234 9555 87676 2344 Expected output: Description of the following table: TABLE1 1234 9555 87676 2344
0
votes
2answers
34 views

Add newline character to file

Hi Guys i need to change the below single line string using a shell script {1:F01NESWSZM0AXXX1111111111} {2:I940BBRUBEBBXXXXN} {3:{108:400MSOG161200FRO}} {4: :20:400MSOG161200FRO :25:1xxxxxxxx65 :28C:...
0
votes
0answers
36 views

awk + how to manipulate awk output

The following awk command prints the results from services file # awk '{print $2}' /etc/services 48002/tcp 48002/udp 48003/tcp How can I manipulate the output so it prints the "service file" ...
0
votes
1answer
63 views

Replace 2 successive lines using sed

I've been trying to replace successive lines with the following sed commands : sed -i -e '/string1/{N;s/string2/string2_replaced/;N;s/string3/string3_replaced}' file1 sed -i -e '/string1/{n;s/...
3
votes
1answer
33 views

Replace a word after matched word with incrementing values

I have a file like this - ! interface csa2549abA xxxx yyyy zzzz ! interface aso23apwoeAe aaa bbb ccc ! interface FastEthernet0/1 ppp qqq rrr ! and so ...
2
votes
1answer
51 views

sed - Use file1 to find replacements contained in file2 for lines from file3 [duplicate]

I'm new here and haven't posted much, I'll try to make this as clear as I can. I want to perform a find and replace that involves three files: find.csv identifies lines containing strings. I want to ...
1
vote
1answer
26 views

Getting rid of a line with a perfect match (not substring) using sed

I want to delete a line which matches the word name but doesn't delete the lines have something following it. I can't seem to find an answer to this. I know sed -i '/name/d' * would delete the whole ...
2
votes
3answers
47 views

linux + ssh + perform two tasks in one ssh and print to CSV

the following command print the two values in one ssh shut ssh test01 "hostname && cat /etc/sysconfig/rhn/rhnsd " test01 INTERVAL=240 but how to change the syntax in order to print the ...
4
votes
1answer
393 views

How do I sort words by syllable count?

How do I perform an ascending sort of a word list, based upon how many syllables each word contains? Example Input: something important dog cat bookshelf Example Output: dog cat something ...
1
vote
3answers
67 views

Delete the nth line from a matched string (which only occurs once in the file)

I have a question related to deletion of strings that appear at the n+2 position after the matched string which is at position n using awk for multiple files. I am able to print it using the command: ...
0
votes
1answer
76 views

sed use to replace string 2 lines after matching pattern in AIX 6.1

I try to replace a character, 2 lines after matching pattern. For this, I'm using this code: sed '/some_pattern/{N;N;s/word1/word2/}' /etc/filesystems > /etc/filesystems.tmp && mv -f /etc/...
2
votes
3answers
87 views

Replace values in file

I have a files: $cat file1.txt 1234|W 1345|S 8427|D 2132|C 3243|V and my sql file is : $cat select.sql SELECT * FROM CUSTOMERS WHERE ID IN (FLAG); and I have a shell with the next ...
0
votes
3answers
32 views

split lines and print it to new line for certain character

I need to split lines and print it to next line when pattern match. Like I have: ABC123xxx:: 2345 ABC345yyy:: 5678 ABC986zzz:: 7955 And I want it to print to new line when ABC pattern will come: ...
1
vote
4answers
65 views

Replace the specified string to its appearance time using sed or awk

I want to replace oooo to 1, 2, 3, ..., like a example below: From > cat demo.snippet snippet anova.cca "anova.cca fun" anova.cca( ,${oooo:object} ${oooo:,...} ,permutations = ${...
0
votes
3answers
51 views

sed substitution

I have a string as follows: /test/test/ 12 /test/test My goal is to turn it into: /test/est/ 12 /test/test This is the command: echo "$x" | sed 's@\(/*/\).@\1@g'" I am using at the moment but ...
2
votes
2answers
78 views

Find (and strip) common initial whitespace from file/pipe

I am looking for a way to find and remove the common initial whitespace from a text stream or file. I do not want to remove all leading whitespace (that would be a simple sed 's/^[[:space:]]*//'). ...
2
votes
3answers
194 views

sed regular expression behaving differently than in vim and perl?

Here's a sample 'test.txt' abcdX1yad45das abcdX2fad45das abcdX3had45das abcdX4wad45das abcdX5mad45das sample desired output: X1yad X2fad X3had X4wad X5mad I could get it working in vim with: :% ...
1
vote
3answers
101 views

Insert single quotes in text file for use as SQL query that follows the open-parens using sed

I have a where clause string in Unix file as below where c1 in (a) and c2 in (a,b,c) and c3 in () Need Output as where c1 in ('a') and c2 in ('a','b','c') and c3 in ('') Would be great if some ...
0
votes
1answer
46 views

Getting “sed: -e expression #1” when trying to run search and replace

I'm using Amazon Linux. I'm trying to run a search and replace using sed. I'm running into the below error ... [jboss@mydevbox nodejs]$ sed -i -e "s/test.smokeTest('(.*?)', '(.*?)', '(.*?)')/test....
0
votes
2answers
51 views

Binding Timestamp with Hexdump?

I am running a script which is given below, sudo hexdump -v -e '1/1 "%02x\n"' /dev/ttyUSB0 | Many Pipes | gawk '{ print strftime(":: %s"), $0 }' Here the data is being hex dumped with timestamp ...
3
votes
1answer
80 views

Use awk as a stream editor

awk is the swiss army knife of text manipulation. If, however, I need to change small bits in a text, I reach out to sed generally. While it might be the best tool for the job, it is worth it to ...
0
votes
2answers
38 views

Sed replace not functioning as expected

I want to replace listen = 127.0.0.1:9000 by listen = '/var/run/php56-fpm.sock' sudo sed -i 's/listen = 127.0.0.1:9000/listen = \'/var/run/php56-fpm.sock\'/g' /etc/php-fpm.d/www.conf Error: bash: -...
1
vote
2answers
20 views

Deleting lines by matching 3rd and 4th character only

I am running a script that fetches me the data as given below, 1400d2b8 1f4d1e2507 1200781e As you can see the 3rd and 4th character is 0 in line 1 and line 3. I am trying to write a single line ...
1
vote
1answer
34 views

How to output multiple lines using a single condition?

I have a file with the pattern: n0 n1 n2 ... ni ------------------------------- N0 N1 <empty line> if N0 is less than a specific number, I want: 2 lines above the N1's line N1's line Empty ...