Questions tagged [sed]

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

Filter by
Sorted by
Tagged with
3
votes
3answers
206 views

sed - replace value to use quotes where needed

I have 100+ jinja template files with 0-k occurrences of "value: ..." string in each of them. The problem is that some of the files are using: value: something some of them: value: '...
83
votes
12answers
32k views

How do I remove the first 300 million lines from a 700 GB txt file on a system with 1 TB max disk space?

The answers I found use sed, tail, head: How do I delete the first n lines of an ascii file using shell commands? https://askubuntu.com/questions/410196/remove-first-n-lines-of-a-large-text-file But ...
1
vote
1answer
50 views

sed + how to append complex line after match specific line

We want to append with sed , the following complex line after matching the line that start with – number_of_cars_are more /tmp/orig_file number_of_cars_are=$number_of_cars_are the line that we want ...
0
votes
1answer
16 views

sed + how to comment parameter that start in beginning of line even if parameter start with tab or spaces

we have the following file more /tmp/file number_of_cars_are=$number_of_cars_are LOG "number_of_cars_are=$number_of_cars_are" echo "number_of_cars_are are $number_of_cars_are&...
0
votes
4answers
54 views

Changing content format

I have a text file which has 1000 rows/entries. These 1000 entries correspond to the column names for my dataframe. These are the new features that need to be added to the dataframe for model ...
2
votes
6answers
332 views

How to make the first character following a semicolon uppercase, for each line of a text file, using terminal

I have a txt file like this John Doe;john Doe is ...;he lives in ... Mike Nelson;mike Nelson works for ...;he makes ... Marcy William;marcy's mother is ...;marcy travels a lot... I want to convert ...
6
votes
3answers
98 views

bash: /usr/bin/sed: No such file or directory

On a test server I purposefully deleted ????? in / - I was expecting the symlink /lib64 and the /media directory to be deleted. All went well (everything broke), but then I was curious about the ...
0
votes
1answer
55 views

Cannot replace multiple whitespaces with one [closed]

I'm trying to remove double spaces and replace them with just one. So far I've tried: sed -i 's/ / /g' ... sed -i 's/[[:space:]][[:space:]]*/ /g' ... tr -s ' ' But none work. Then when I go to the ...
0
votes
2answers
17 views

Replace PATH element with SED of multiple xml file in bash

I have managed to replace 1 xml file. However, I have 10 of them from test1.xml to test30.xml and they have different Paths at the end: test1.xml ... <examples> <example path='/test/test123/...
1
vote
3answers
58 views

how to search and replace PATH element with SED of xml file in bash

I would like to replace the current element inside example path tag from: ... <examples> <example path='/test/test123/test12345.txt'/> <examples> ... to ... <examples> <...
-2
votes
4answers
42 views

when found blank line change to new column [duplicate]

I have a data as: q w e e r r t 23 21 1 Whenever we find blank line change it to new column. Output q,e,23 w,r,21 e,r,1 ,t, I have tried but neither with sed nor I ...
0
votes
1answer
27 views

Extract characters according to pattern, but only between either of two range start patterns and a common end pattern

Data (some-mutool-clean-pdf-file) to operate on is something like the following, whilst leading numbers are not part of the data, but hopefully serve to clarify my problem: 1 blabla 2 /Span <</...
-1
votes
3answers
26 views

How to grep lines for a specific profile starting with [default]

I'm trying to parse the lines of an .aws/config or .aws/credentials file of a specific profile such as [default] or [prod]. File example [default] region = us-east-1 output = json [nonprod] region = ...
2
votes
1answer
29 views

Replace value on a particular column in pipe delimited file at specific row – sed or awk?

I have a requirement to replace a specific column value (identified by location) with another value on a pipe-delimited file at specific row. sample file: a|abc|val|sum|temp bs|run|win|can|done jump|...
0
votes
1answer
17 views

Query on updating a Config file

I am new to scripting and would need assistance in one of my requirement. I have a config file having below information Run=YES I want to update the value to "No" through script. Below is ...
1
vote
2answers
33 views

How to remove duplicate paragraphs

Given a file with paragraphs (group of lines separated by a blank line). It is guaranteed that the line breaks within equivalent paragraphs are conserved. Is there a way of using uniq to remove the ...
0
votes
5answers
72 views

sed to extract lines following a starting group pattern

I currently ran into a problem that needs some help solving. Even pointing in the correct direction would help. I have a file with lots of lines and want to extract only specific 'group' of lines if ...
-1
votes
1answer
42 views

Remove all the occurrences of a word except the third and second last occurrence using sed

I am trying to Remove all the occurrences of a word except the third and second last occurrence using sed for example if input is : 1 liam 2 liam 3 liam 4 liam 5 liam 6 liam Output should be: 1 2 3 ...
0
votes
1answer
22 views

how to sed string with spaces in between?

before string: file_csv_max_size: 100 # in bytes after string: file_csv_max_size: 200 # in bytes I tried below but did not work.. sed 's|file_csv_max_size: 100 # in ...
1
vote
0answers
60 views

sed escape sequence for “\ ” not working [closed]

I am writing a sed process and am getting the following error: "Escape sequence "\ " is invalid." I am looking to replace text that is similar to, so that the backslash space just ...
-1
votes
2answers
43 views

How to replace all characters in string that dont match a pattern in sed?

I have a string such as "something_something_something" Now the string must have the pattern: ^[a-zA-Z0-9](-*[a-zA-Z0-9])* How can I replace all characters in the string that dont match the ...
0
votes
1answer
35 views

select rows based on specific column values [duplicate]

How can I select all rows in a text file based on different values of a particular column? The desired values are not in a specific interval. A short example of what I expect is given below. My data ...
-2
votes
7answers
119 views

Add '/' around every character of a string

How can we use sed or awk to translate unix to /u/n/i/x/. I was able to do this with Python as follows: separator='/' separator.join(string)+separator But how can we achieve this in Shell?
8
votes
11answers
516 views

How do I print the last sequence of lines between a start and an end pattern?

Answers to this question: How to grep lines between start and end pattern? are not concerned with multiple sequences of lines which fall between the match patterns. Thus, for example, sed -n '/...
4
votes
4answers
796 views

Delete a lot of words with one command

I have a lot of links like https://content.example.net/skin/frontend/2015/default/fonts/test.ttf https://content.example.net/skin/frontend/2015/default/img/test.svg https://content.example.net/skin/...
0
votes
3answers
61 views

Extract a list of strings from a file, only from first column

I wanted to extract a list of numbers (string.txt) from masterFile.list. masterFile.list is separated by | and contained more than one column. I am only interested with the line, where its first ...
0
votes
3answers
49 views

extract virtualhosts to individual files based on virtual hostname [closed]

I want to extract each VirtualHost from /etc/apache2/sites-enabled/default-ssl.conf and put then into their own config files there are lot of entries in 1 single file and managing them is becoming ...
3
votes
6answers
88 views

Using sed to replace substrings between specific tags

I want to combine two sed command in one and really don't know how to do it, I've tried multiple things without success. For the result I want all slash between a specific tag to be replaced with ...
0
votes
2answers
49 views

Bash Script: Add/Remove comment on the matching lines

I have a file ~/.zshrc with the following lines ... #export PATH="/usr/local/opt/php@7.0/bin:$PATH" #export PATH="/usr/local/opt/php@7.0/sbin:$PATH" ##export PATH="/usr/local/...
-1
votes
1answer
28 views

Use sed to remove part of a line

How can I remove with sed part of a line захватывающее состязание смелых героинь и героев с профессионалами. &quot;}},&quot;has_video&quot;:1},&quot;trailer&quot;:{&quot;...
-1
votes
6answers
70 views

Change all positive values to negative and vice versa but in two different files

I have two data files one.txt and two.txt on a Linux system. I want to convert all positive values to negative in one.txt and vice versa for two.txt, but only on the first column. Please note that ...
0
votes
2answers
63 views

Parse a YAML section using shell

I have a YAML that looks like something: - whatever: - something - toc: 4 - body: assets/footer.html pkg: - pkg_a_1: - Shass - AJh55 - ASH7 - pkg_b_1: - Kjs6 - opsaa other: ...
0
votes
2answers
27 views

Print only one value from duplicates [duplicate]

I have following content in a file. $ cat file.txt code-coverage-api jsch cloudbees-folder apache-httpcomponents-client-4-api apache-httpcomponents-client-4-api jsch apache-httpcomponents-client-...
0
votes
4answers
252 views

Remove comments from file while ignoring quoted comment signs

I would like to remove comments starting with # from a file. I have tried the simpler approaches described in How can I remove all comments from a file? but I have a few additional rules: A # does ...
1
vote
6answers
78 views

How to make sed get first occurance rather than the last?

My string : <p> <strong>Linux x86_64/AMD64/EM64T</strong><br> Latest Long Lived Branch Version: <a href="https://www.nvidia.com/Download/driverResults.aspx/163238/en-us&...
-4
votes
3answers
54 views

So I have a wordlist that I'm creating suited for a particular domain and I'm trying to get rid of the forward slashes [duplicate]

Basically I want to get rid of the forward slashes but I'm not as familiar with sed/awk as I should. Can someone help me out here. Edit: I'd also like to mention that the worlist is over 1000 lines ...
0
votes
1answer
25 views

extract pdf files from an index.html already downloaded in order to wget them, even when there are multiples pdf with grep

I have an index.html file containing href link to PDF files. When I do : grep -i 'href=' index.html, I get for example : <p>Télécharger : <a href="https://ecole-euclid.cnrs.fr/wp-content/...
0
votes
2answers
46 views

Split Column into multiple column when there is blank column

I need some help: A B C 1 2 Q W A Whenever we find blank column split the column into new column. Output: A,1,Q B,2,W C,,A I have used Sed but I am not able to find keyword to split. Is there a ...
0
votes
4answers
88 views

Print matched pattern and previous lines until a linebreak or a space, using sed or awk

I want to print the "tmp and lines before until a line break", I'm a newbie to Unix. EX: Input AAA CBH VFh GFD DFC VGF HGD TMP JHG TFD PI1 98A TMP TMP 765 UBS My desired output should be ...
-1
votes
0answers
25 views

sed changing the parameter from 10 to 3 in line containing certain information

I have a file containing: hard maxlogins 10 I want change the value from 10 to 3. hard maxlogins 3 I appreciate any information you can share with me
-3
votes
0answers
27 views

Greping StackTrace error in Unix

I want to grep StackTrace error and its caused by in unix. Please suggest with unix commands LOG: 2020-09-03 22:14:26,779 INFO [stdout] (ajp-/10.78.194.31:9011-612) <div style='font-size:11px;font-...
-5
votes
1answer
46 views

Split single column in multiple row and then format the data

I need some help I have data in below format in a single column: A:1 B:2 A:3 C:8 B:2 C:4 B:2 Need an output in below format: A,B,C 1,2, 3,2,8 ,2,4 Kindly suggest!!
0
votes
2answers
27 views

Remove request parameter values

Consider a list of string/URL in a file as shown below $ cat urls.txt https://example.com/index.php?param1=value1&param2=value2&param3=value3 https://example2.com/home.php?param1=value1&...
0
votes
3answers
46 views

Remove lines that do not match in bash

I've got a text file containing Today, 12:34https://... Today, 12:43https://... Yesterday, 13:21https://... Nottoday, 12:32https:// and would like to delete all lines that do not match with "...
-2
votes
2answers
61 views

Using SED and/or AWK to replace line with pattern [closed]

This is the input file def test(): print('do something') #>#> this does something return 0 def new_test(arg): # >#>this too does something x = 0 y = 1 return ...
0
votes
5answers
71 views

How to “paste” two files without writing to a new file? [closed]

I am doing this for pathname in /user/home/file_*; do cat "$pathname" | sed -n '3p'; printf"\n"; done> user/home/foo; for pathname in /user/home/file_*; do cat "$...
0
votes
3answers
49 views

How do I “join” in awk, or otherwise trim a trailing /?

echo -n "refs/heads/feature" | awk -F '/' -v OFS='/' '{ print $3, $4 }' | sed 's/\/$/g' sed: 1: "s/\/$/g": unterminated substitute in regular expression if I removed the sed this ...
12
votes
2answers
981 views

View POSIX draft standards

The GNU sed manpage says: The -E option switches to using extended regular expressions instead; it has been supported for years by GNU sed, and is now included in POSIX. However, POSIX Issue ...
3
votes
7answers
408 views

Extract paired lines

I've got a txt file like this. There are paired lines email-password and email-hash. EMAIL:user1@site.com PASSWORD:pass1 EMAIL:user2@site.com PASSWORD:pass2 EMAIL:user3@site.com PASSWORD:pass3 EMAIL:...
0
votes
4answers
58 views

Need a script or command to append the previous line with the current line that starts with a lower case letter

The output I'm trying to format before opening the file in excel looks like this: 1. |1.99934| BD | 1| C 1 - H 2 | 60.12%| 0.7754* C 1 s| 24.99%|p 3.00| 74.95%|d 0.00| 0.05%| f 0.00| 0.01%| |...

1
2 3 4 5
116