Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [sed]

"sed" ("stream editor") is a Unix utility that parses and transforms text files.

1
vote
0answers
9 views

remove trailing slashes recursively on php files on windows with cmder

I need to remove all trailing slashes on php files. I use cmder on windows. I use this command to find the files, but they are a lot. find ./ -name "*.php" | xargs grep -c -P '\s+$' | grep -v ':0$' ...
0
votes
2answers
48 views

Add prefix to each lines of file from other file

I have two files named file1.txt and file2.txt, I'm trying to add the prefix to file2.txt from file1.txt in a manner so I can pipe the results to the next utility I'm using. cat file1.txt aa bb cc ...
0
votes
1answer
28 views

Mac terminal : Sed regex, extracting part of a string

I have a string , exactly a file path /Users/dengjiangzhou/Documents/源码/198/李宏毅-机器学习2017秋季.txt, I need to extract the path of its folder , to get /Users/dengjiangzhou/Documents/源码/198/ . Here is ...
0
votes
2answers
38 views

How can I insert the original matched pattern (OLD STRING) into the result (NEW STRING) Using Microsoft Word's Find/Replace Feature?

Microsoft Word's find/replace feature seems like it is many-to-one. Suppose that we have a word document numbers surrounded by parentheses, such as (6) and we want to remove the parentheses and place ...
1
vote
4answers
85 views

awk, sed, or other text processing suggestions, please

I have the following repeating pattern of text that needs to be reformatted. Normally this should be easy, even with a standard text editor, but in this case I need to expand the information in the ...
0
votes
1answer
47 views

reformat string using sed

I have a file containing lines ["foo"] = ".worldport 0 322.373138 -1487.853882 43.720089", ["bar"] = ".worldport 0 386.938000 212.299000 43.699400", ["baz"] = ".worldport 0 1239.120000 -286.705000 42....
1
vote
2answers
31 views

Comment xml segment using shell script / command

I am trying to do a shell script with 2 parameters. xmlcomment -c cholo or xmlcomment -u cholo Given the following xml file, <?xml version="1.0"?> <guyList> <guy> <name&...
0
votes
2answers
70 views

Is sed buggy when pattern is newline for a delete command?

My goal is to print the content of a file up to (and excluding) a specific pattern and I'm using the following which works as expected (even when pattern is ^$): sed -n '/pattern/!p;//q' file In ...
0
votes
1answer
33 views

In bash shell assign output of sed s/^#…/&/' to string variable?

Let me be specific: NOT using variable in sed 1st command but assigning sed output to variable in bash shell, THEN using variable in 2nd sed command to append variable string to end of string in ...
0
votes
1answer
36 views

SED - complex text deletion and pattern matching

I searched allot on SED. I'm new to using it. Managed to make a command that deletes a block of text between PATTERN-1 and PATTERN-2 (including the patterns) in a large (250mb+) text file. Now I have ...
3
votes
5answers
748 views

Multiple sed commands in Bash

I have a a file usernames and passwords in JSON format that I want to convert to process. I have used sed in different commands to process it but what I would like to know is how to lump all three ...
0
votes
1answer
44 views

Replace lines after a given number of matches on separate lines with AWK

Currently I'm using AWK to find and replace a portion of a string after the first three occurrences of a pattern. The string is formatted like this: func(tempID="39849235",count='12');, and there are ...
-1
votes
1answer
22 views

Manipulating output - awk|sed|grep

I would like to maniputate the following output like this: Output: S* 0.0.0.0/0 [1/0] via 1.1.1.1, MAR-LNK-VGL_DSL [1/0] via 2.2.2.2, MAR-LNK-GVT_DSL [1/0] ...
0
votes
0answers
18 views

sed's substitute function equivalent in Windows

I'm looking for the native windows command to execute something similar as Linux sed's substitute command as follow. Sed in this example was taken from UnxUtils Would it be possible to produce ...
1
vote
1answer
62 views

sed - delete lines taking patterns from external file

I'm looking for a way to delete certain lines in a file taking patterns from external file. The best way would be to use sed. I was trying several articles, like this, but they doesn't answer my task. ...
0
votes
1answer
24 views

How characters can be inserted to strings belonging to a column resulting from an intput command using awk and sed

Here is a formula that has appropriate foundation for my purpose – among others it prints files only, using for sizes powers of 1024, 2^10 –. Involved file's size is 1382 bytes (1,35 KiB): # ls -lh | ...
0
votes
2answers
68 views

replacing 6000+ strings in >2GB text file

I'd like to search and replace more than 6000 strings in a > 2GB text file. sed -i "s/search/replace/g" 2gbfile.log is taking forever. Especially if you have to do it 6000+ times. So I came up with ...
1
vote
1answer
48 views

How to extract all strings in require('')?

My source files are something like this: abl require('../img/a.png') require('../img/b.png') bla require('../../img/c.png') ble <Image source={require('../img/d.png')} My expected output is: '../...
11
votes
1answer
1k views

Replacing [0-9] with [A-J] not working with sed

I am working on a command that replaces all digits 0-9 with their corresponding letters in sed. I know I'm doing something wrong, but sed is not interpreting the replacement regex as anything but a ...
0
votes
0answers
125 views

Lookup-table text replacement in bash

We have weird usernames in our Linux system (like user0001). I would like to pipe results of ls -l through a lookup-table replacement of the weird usernames by their real names. I can make such a ...
13
votes
4answers
1k views

How to recursively replace characters with sed?

Is it possible to replace occurrences of a character sequence recursively without iterating over the same sequence again? By performing a sed as in the following scenarios I can get the mentioned ...
2
votes
2answers
35 views

replace number with star specific pattern for whole file

In my file I want to replace number to * Example: data[0] ---> data[*] I have data[0] to data[127] and also want to do for the whole file. So how can I do only for number? I tried with command ...
2
votes
2answers
55 views

Sed Script to Capitalize “I”s in a Text File

I am trying to create a sed command that capitalizes the pronoun I in a text file. For example "i like dogs." should be "I like dogs." So far I have: sed 's/ i / I /g' This doesn't work in a ...
0
votes
2answers
26 views

UNIX: Using sed, how to print every 1st and 2nd lines in sets of 4 lines?

My file has multiple sets of lines. Each set has 4 lines. Line 1-4 is set 1. Line 5-8 is set 2 and so on. I need to print the first two lines from every set i.e line 1 and 2, line 5 and 6 and so on. ...
1
vote
0answers
161 views

sed: How to replace variable line if found or append to end of file if not found?

So my question is very much based off of a related question, but has one key difference. In the answer given of: sed '/^FOOBAR=/{h;s/=.*/=newvalue/};${x;/^$/{s//FOOBAR=newvalue/;H};x}' infile I've ...
0
votes
1answer
41 views

How to convert “yyyy-mm-dd” to “dd.mm” in column of text file using awk (or sed, etc.)?

Let's consider that we have the following line in text file: ... 2018-09-13 5555 33-33 Some_string ... I need to change first column (date as yyyy-mm-dd) to other format (dd.mm, dropping ...
1
vote
1answer
33 views

mac: concatenate contents of text files across many directories; append directory names to corresponding text file contents

In the following directory structure: directory1 -subdirectoryA ---fileA.txt -subdirectoryB ---fileB.txt subdirectoryC ---fileC.txt I would like to generate a text file containing the following ...
0
votes
1answer
41 views

How to use sed to remove "(double-quotes) on code lines while leaving them on real comment lines in a vimrc file?

On Ubuntu(Server/Desktop), I wish to remove a single " (double quotes) character from the beginning of lines in my /etc/vim/vimrc. This should be done for all lines that start with a ", but not if ...
1
vote
3answers
96 views

How to get a line using a pattern before a line number?

I need to get a line which matches a pattern before a certain line number of a file. Example: linenum 1.fruits linenum 2.cherry linenum 3.apple . . linenum 7.orange linenum 8.apple2 . . . linenum 20....
2
votes
2answers
63 views

How do I transpose a table with repeated key values?

I have a table that looks like this: Column A | Column B 10 | 0.1 10 | 0.2 10 | 0.3 20 | 0.4 20 | 0.5 20 | 0.6 I need to transpose ...
0
votes
1answer
43 views

how to align lines to the left side with sed or perl one line liner

we have the following file how alignment lines to the left side with sed or perl one line liner more conf.env # Extra ssh options. Empty by default. export HADOOP_SSH_OPTS="-o ConnectTimeout=5 ...
0
votes
1answer
32 views

How to avoid Sed changing the file format?

I was trying to use a sed file to preprocess a file, but the output from sed seems to change the format. How should I avoid it? file A.txt A.txt UTF-8 Unicode English text, with very long lines sed ...
0
votes
1answer
365 views

Regular expression to match opening double quote missing a ending double quote

I have a large (25 million rows) data file that is pipe (|) delimited. The data vendor provides files and I run automated jobs to load the files to a Redshift database and then process the data. The ...
0
votes
0answers
45 views

Sed doesn't works over variable

I'm trying to combine find -exec command with a function that should strip the relative path and copy to another place (with same tree). The script looks like the follows: function makeLinks(){ ...
0
votes
1answer
67 views

How to exchange two patterns in place with `sed`?

I am using sed command to change <active>true to <active>false in an xml file. Now if I use sed 's/<active>true/<active>false/g' file.xml > file.xml it completely erases ...
-1
votes
1answer
225 views

Sed does not exist for windows 10 64bits but?

I have the following unix script : ZECOM = /path/to/command/dothis for FILEg in *g.F do echo $FILEg FILE=`echo $FILEg | sed 's/g\./\./' | sed 's/\.F/\.f/'` $ZECOM -someoption -f ./optionsfile.sh $...
0
votes
1answer
66 views

How to create multiple html tables from multiple csv files using a shell script

I have two csv files like this: test1.csv: user size aaa 10 bbb 20 ccc 30 test2.csv: name value www 5 mmm 8 ppp 9 I want to convert this to two separate HTML tables using a shell ...
0
votes
0answers
22 views

SED -f FileParams.txt FileIN.xml > FileOUT.xml

I have a problem with sed Command im need to substitute parameters from the FileParams.txt on the FileIN.xml and generate the FileOut.txt My issue is that all params that i have in the FileParams....
0
votes
1answer
83 views

How to replace a character in an interval delimited by two other characters from a file

I have to replace all occurrences of the vertical bar character | with a comma , when they appear between [ and ] characters, on each line of a file. Let's say I have the below string in the file: ...
0
votes
0answers
38 views

How is it possible to “sed” through a port?

For example: The telnet daemon server is echoing "Hello there user." For the sake of the example, say the version of the daemon cannot be changed at the moment and we have to make a better greeting. ...
0
votes
2answers
1k views

how to extract json file using awk/sed?

Input data.json { "lastUpdateTime" : "2018-07-20T10:56:26.000Z", "items" : [ { "date" : "2018-07-19T21:09:27.000Z", "user" : "dddd", "size" : 5219402, "rawSize" : 15658206, "...
-2
votes
2answers
71 views

Append console out to file at begin [duplicate]

To postgenerate fake-module-bpy (For blender Python)... нowever, the language does not matter. So, I use next console command ]$ ls | grep -v _init_ | sed -E 's/^([a-zA-Z0-1]+)/import \1/' >> ...
2
votes
2answers
1k views

Remove every line breaks following carriage return (^M) and join the lines

edit: Now that I got answers, I marked one by @KamilMaciorowski that fits better to the title as an answer, but this answer by @oliv actually were better suited to my actual need to my primary purpose....
1
vote
1answer
757 views

append to end to line without newline

When i try to append to the end of a file it creates a new line. Now I have tried to fix this with echo -n but that doenst work. So what am I trying. I'm trying to get the following result: Hello ...
2
votes
1answer
441 views

How to concatenate two lines with `sed`?

I am trying to concatenate two lines of iwlist output. My grep and sed commands to remove leading and trailing spaces work fine but I can't get the last sed statement to remove the \n to work. What am ...
0
votes
3answers
101 views

sed regex with '+' doesn't work - why?

I don't understand it. I'd like to replace the ip-up 9490:notify_rc string to ip-up ****:notify_rc. I thought it's simple: echo "ip-up 9490:notify_rc" | sed -e 's/ip-up [0-9]+:notify_rc/ip-up ****:...
0
votes
1answer
51 views

Replace an entire word based on pattern using SED

I have a bunch of virtual machines that I deploy over and over again in a large automated test environment. Each VM, after it gets deployed, writes its hostname to /etc/hosts. 127.0.0.1 XXXX-...
0
votes
2answers
53 views

How to loop through a directory or list of files with a wildcard in a Bash script?

I'm trying to anonymize my Apache logs after 7 days and actually I have already some trouble to write the skript for anonymizing. My script replaces the 3 first digit with X and it works properly ...
0
votes
1answer
29 views

sed to insert a comment character over a remote connection

I want to search a file for the occurrence of the word Logmon anywhere on a multi-lined file. For each row where a match is found, insert a # at the beginning of the row. I am able to accomplish this ...
0
votes
0answers
40 views

My aim here is to diff two xml files(while ignoring certain lines) and output it to another file in makefile

When I use below code in Cygwin terminal, it works fine: diff <(sed '/dmFile/,/layout.oa/d' C:/cygwin64/home/tkarmaka/coilsys_regression/tests/native/Workspaces_Gold/Jazzsbc18h2_gold_wrk/test_info....