Stack Exchange Network

Stack Exchange network consists of 175 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 is a command-line stream editor for filtering and transforming text.

0
votes
1answer
40 views

How do I exclude pre tags from HTML minification using sed?

I am trying to minify HTML using sed My problem: I don't want to minify anything inside <pre> tags, but can't make it work.. Here is what I am using: sed ':a;N;$!ba;s@>\s*<@><@g' $...
5
votes
8answers
303 views

Separate the element after every 2nd ',' and push into next row in bash [duplicate]

An example of my file looks like this: 201012,720,201011,119,201710,16 Output I want: 201012,720 201011,119 201710,16
0
votes
1answer
35 views

List lines that are the same in the second part but differ on the first part

Suppose that you have a big file with lines of this format: A, B, C, D (each line has 4 parts comma separated). I need a list of all the lines which have common fourth part (D is the same across those ...
5
votes
2answers
106 views

Comment from start of file to a pattern matched line using sed

I search a pattern, say 'START OF ARAMBOL' and it is matched in a file. Now I would like to comment every line from the line no 1 to the current matched pattern line no. I have to do it for more than ...
0
votes
0answers
47 views

How can I find in a log a specific timestamp [duplicate]

This is something I really need on a daily basis and it's really hard sometimes I need to get logs from a specific date time from a log file. This is an example of the file INFO | jvm 1 | main ...
0
votes
3answers
30 views

Sed not outputting matches from regex to file

I have a file (data.txt) which contains strings like this: [?1h= => ["AD070517", "AD070518", : ESCESCOOBB "AD070809", "NE0000013", "NE0000014", : ESCESC[[66~~ "LG100085-097", "LG100085-098", ] ...
0
votes
4answers
36 views

Read the data page wise and store in seperate files

I have a huge text file where data in seperated pagewise.for example The Text is in below format i want to read lines page wise and store in seperate files Page 1 line 1 line 2 line 3 line 4 ...
0
votes
4answers
36 views

change format of column

I have in the input file a column with the following format H6 H7 O4 C4 H8 H9 O5 C5 H10 H11 I want the output to have the following format "a H6" "a H7" "a O4" "a C4" "a H8" "a H9" "a O5" "a C5" "a ...
1
vote
1answer
34 views

How to move lines containing specific text to top of file in same order as code executed?

How to move lines containing specific text to top of file in same order as code executed? Here is the code I have: printf 'g?_001\|_002\|_003\|_004\|_005?m0\nwq\n' | ed -s target_file ( credit ...
1
vote
3answers
66 views

How to move lines containing specific strings to top of file?

How can I move lines containing specific strings (ie. 005, and 007) to the top of the target file? Contents of target file: XXX_008 XXX_001 XXX_002 XXX_009 XXX_003 XXX_006 XXX_005 ----> located ...
0
votes
1answer
32 views

How to group a string that has multiple words with awk? (Prints lines between 2 patterns)

I have an issue in which my string its not a single string; it is a string with multiple words; in which using sed works great; but not with awk; How can I group all that string with awk? I tried to ...
1
vote
3answers
36 views

read file and based on criterion print desire output

I have input file which looks like this: H1 O1 C1 H2 H3 O2 C2 Br1 I want to have an output file which to have the following output H1 = 1 O1 = 8 C1 = 6 H2 = 1 H3 = 1 O2 = 8 C2 = 6 Br1 = 35 So when ...
1
vote
2answers
39 views

Update rows by referring another file

I have two comma separated files as mentioned below, cat source.txt A,1000 B,3000 C,2500 D,5000 E,4000 F,3000 cat test.txt A,1000 C D,5000 B E How can I update file test.txt by referring file ...
0
votes
1answer
21 views

Using sed to insert README.md in .gitignore

I'm attempting to use sed to insert README.md as the first line in the file .gitignore. This is what I have: ole@mki:~/test$ cat .gitignore line1 line2 ole@mki:~/test$ sed '1 i README.md' ....
0
votes
3answers
34 views

How to find and replace seemingly a tab char using sed?

I have a line looks like this: some.com *.some.com The space is seemingly a tab space because when I move the keyboard arrow, one move will move me to the end of it (it does not seem multiple ...
0
votes
2answers
34 views

How to find more than one space and replace it with one space?

I want to find repeated spaces (more than one) and replace them with one space. I tried: sed -e 's/ []+/ /g' myfile.txt > myfile2.txt This resulted in an empty file. Why? and how to achieve my ...
0
votes
1answer
16 views

How to express beginning and end of line in sed

I want to use sed to replace every '} that comes at the end of the line to "}. I wrote: sed -i -e "s/'}$/\"}$/g" But this replaces it to: "}$. What is wrong? How can I use regex in my sed to express ...
5
votes
4answers
76 views

how to insert new line if a line has more than 60 characters

I need to turn a text file that has a single line per file name and output separated by a single space into specific blocks that have lines that are equal to 60 characters in length. Like this: >...
2
votes
2answers
95 views

How to insert a name of the file as a header of a file?

Example: File name: ENSG00000000003 ENSG00000000003 43120.829491094 ENSG00000000005 39604.4956791524 ENSG00000000419 7645.05624570546 ENSG00000000457 2157.49855156382 ENSG00000000460 3317.98417717746 ...
5
votes
5answers
381 views

Extract the characters before last colon

I need to extract the characters before last colon : and also remove the square brackets [] in the last line. My file structure is 256.XXX.XXX.X:20234 214.XXX.XXX.X:7249 [2200:XXXX:XXXX:XXX:XXXX:XXXX:...
2
votes
4answers
168 views

Grep value of a specific key from a String, concatenated of key : value pairs

I have a string which is concatenation of "key":"value" pairs separated by "," like- KEY1:VALUE1, KEY2:VALUE2, KEY3:VALUE3 From this string, I have to grep for a specific string -- let's say KEY2 -- ...
1
vote
1answer
44 views

Using sed within a makefile

I want to modify the cygwin path to the windows path from within a makefile. For that purpose, I am using CURDIR := `pwd` WINDIR := $(shell echo $(CURDIR) | sed -e "s/\/cygdrive\/\(.\)/\1:/" | sed -e ...
2
votes
2answers
41 views

Using sed in alternate line

I have a file with pattern as below: 12345.ABC9998 12345555.abc:ffr.abc-MKDHJKSJJDOKSOKSDCKJODCKJ 12345.ABC9998 12345555.abc:ffr.abc-MKDHJKSJJDOKSOKSDCKJODCKJ I wanted to delete everything before ...
-1
votes
0answers
28 views

Compare 2 days and MTM on current day should not be zero when the deal value doesn't exist [on hold]

There are two files: one for each day. I need to sum the MTM (column6) value based on the Deal (column2). Like adding the MTM value for the same deal values for each file. After adding and getting ...
1
vote
2answers
52 views

Bash - print first line of textfile (csv) bold

I have a text (csv) file like this: Date:;Time:;Value:; 20181202;112044;38274658392; 20181207;121356;94843726283; 20181221;221012;93938272189; 20181230;071234;93736473783; 20190107;011022;27339393022;...
0
votes
1answer
29 views

How to search for a newline that is not preceeded by } and remove it

I want to use sed to search for line breaks that are not preceded by }. The regex for identifying theses cases is: [^}]$ . What I want to say: If the line ended without } then remove the new line. ...
0
votes
2answers
43 views

How to delete string other than pattern?

I have a m3u file as below. I want to delete all strings except the pattern and next first line. or save the pattern and the next first line as another file. Patterns group-title="TR ULUSAL" , group-...
1
vote
0answers
32 views

What characters do I need to escape when using sed? [duplicate]

I need to replace the below text using sed from='[\"test"]' to='test' I tried the command sed -i -e "s|$from|$to|g" but this throws an error: sed: -e expression #1, char 57: Invalid range end
1
vote
3answers
86 views

What does these two commands

I have a script that I do not quite understand yet. The script assigns a configuration file to a hardware. I do not quite understand the following two lines: export TYPE=$(dmidecode -s system-...
1
vote
2answers
133 views

Rearrange columns separated by : in LINUX [closed]

The question is how to rearrange the column along with values in desired order. input "a":"val1","c":"val2","b":"val3","d":"val4" "a":"val1","b":[],"c":"val3","d":"val4" "a":"val1","d":["val2","...
0
votes
2answers
30 views

Replace pattern in all columns except in specific column

I would like to replace "colon" from each columns except from first column as it is. ]chr9:67290502]N SUPP_VEC=011 SVLEN=0 SVTYPE=TRA 0 0 0 0/1:NA:58745598:23,0:--:.:TRA:BND00068094:NA:NA:...
0
votes
1answer
31 views

Using Sed in a for loop with a regular expression

I am trying to modify a json file using a for loop to loop over a list of sample names and use sed to fix those sample names. Right now a subset of the input file is; "WA82671", "WA8267-...
1
vote
2answers
32 views

Read a line then append pound sign (#) at the start of it based on a condition

I have a bash script which reads a file having multiple line of text and executes a command on those lines. Sometimes the command work, but sometimes it fails. I want to append a pound sign (#) at the ...
0
votes
1answer
23 views

How to insert text in a file after particular pattern in shell script?

I have to insert some text after matching a pattern in between a line. core: [dev][delta3=deltafile;delta3dir=755|workpm][staging=stageingfile] Expected output is: core: [dev][delta3=...
0
votes
2answers
37 views

String to replace in shell upto certain context

I want to replace string in file using sed/grep but the string is mingled with another strings Example: sed -i 's/php/vinu/g' test.yml # to replace string php with vinu test.yml php phpehealth ...
1
vote
3answers
47 views

sed command using regular expressions to replace the major minor and release number

I am using Sed to replace the major, minor and release number in version. In my case: version=10.2.0.1 (version=major.minor.release.buildnumber) I don't want to change buildnumber in this ...
2
votes
1answer
49 views

Sed operations are not working or might i am doing it wrong?

input: text: chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 chrX_143483110-chr_6103649147 chrX_143483004-chr6_103649293,chrX_143483110-chr6_103649291,chrX_143483110-chr6_103649053 ...
1
vote
2answers
22 views

Replace string in specific line at specific position of fixed-length file

I have a fixed-length data file where records are tagged (first 6 characters have a certain string that identifies the record) and I need to replace text from a specific line and a specific position ...
0
votes
1answer
52 views

Split stdout on delimiter and select line at random?

How can I split the output of a command on a delimiter, in this case a new line, and then select one line at random? An example of what I'm trying to do is: curl -s http://www.compciv.org/files/...
0
votes
1answer
48 views

how to make my sed command work in GNU works in BSD

I have a block content in my ~/.ssh/config. begin with a line '# BEGIN AUTO GENERATED CONTENT' and end with a line '# END AUTO GENERATED CONTENT' I have a command replacing content between this two ...
0
votes
4answers
46 views

how to capture IP address from info

by the following api we can get the info about master1/2 machines curl -sH "X-Requested-By: ambari" -u "admin"":""admin" -i http://192.23.39.2:8080/api/v1/hosts?fields=Hosts/host_name,Hosts/ip | ...
0
votes
1answer
38 views

Calculate the time difference between two columns in time format hh:mm:ss

I want the time difference between column 5 & column 4 My Input: DATE TIMESTAMP ID START TIME END TIME 2019-04-05 13:57:19 1607 13:06:42 13:07:12 2019-04-05 13:58:00 2327 13:57:26 ...
0
votes
1answer
52 views

Insert characters at the middle and the end of a line with specific line length

Currently I am working on a folder of files, and each file have some lines as follows: abcde fghij abcde fghij jklmn pqrst ..... ..... These lines have a specific line length 43. At the ...
-1
votes
2answers
38 views

Sed not finding file if it's quoted [duplicate]

I have a shell script that's executing a sed command. Upon variable expansion, it quotes the filename. sed -i "$3d" $filename becomes sed -i 1d '~/file' as shown by the debugging flag -x. When ...
0
votes
0answers
21 views

Remove unwanted fields in source file itself [duplicate]

I have file like below with four fields separated by space.I want to keep only field1 in the input_file. With awk '{print $1}' input_file > output_file we can extract the required field and re-...
7
votes
7answers
940 views

Copy previous line to current line from text file

I have a file with lines, just like this: A B C I want to create a duplicate file in bash that contains each line merged with the copy of next line, like: A;B B;C C;
1
vote
3answers
74 views

If line contains pattern, print variable to column

I have the file DEMLIR-GEO_OPT-1-distance-1.coordLog: REQUESTED STRUCTURE DATA Distance vector r(i,j) between the atom i and j in ANGSTROM r(1,5) = 0.944776 0.190651 1....
0
votes
3answers
50 views

How to keep the content of a replaced string with sed

I am trying to use sed to replace a line of text that will keep the found text intact and add a colon to the end of it. specifically, in a file there are a bunch of lines in this format ...
0
votes
4answers
66 views

shell script - Remove character before a specific pattern

I've my /etc/hosts : #192.168.54.144 name1 #192.168.54.144 name2 192.168.54.143 name3 I would like to remove all character # which is followed by an ip address Ipv4 to obtain that : 192.168....
0
votes
3answers
47 views

Unintended line breaks in csv file

I have a csv file with some unintended line breaks. The file looks more or less like this: col1; col2; col3; col4 1a; 1b; 1c; 1d 2a; 2b; 2c ;2d # this should be ...