Questions tagged [sed]

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. It is commonly used to search-and-replace in text files. If your question is about text-processing, this tag is likely to be appropriate

Filter by
Sorted by
Tagged with
0 votes
1 answer
13 views

Replace simple text in the end if line with sed

I have that text #!/usr/bin/env python and I want to replace python with python3 (without regex) but I want to make sure that this text in the end of line. I tried this command: sed -i 's/python\n/...
user avatar
5 votes
3 answers
572 views

How can I capitalise a word proceeding a specific word

Lets say I want to capitalise the first word following the word jumped. Example below Original text: the cow jumped over the moon Amended text the cow jumped OVER the moon I have tried awk and sed ...
user avatar
2 votes
1 answer
20 views

insert variables from 2 files based on 1 row

I have 3 source files. 1.txt - template. <field name="COL1" label="COL2" data-source="COL1" classes="attribute" category="Attribute"/> 2.txt - ...
user avatar
  • 776
3 votes
2 answers
177 views

Trying to uncomment unattended-upgrades lines with script, need help

I've recently started working as an IT person in a all Linux company, and noticed some of the tasks we do can be 'easily' automated. Today's task to automate is installing software and configuring /...
user avatar
0 votes
1 answer
32 views

sed: -e expression #1, char 32: unterminated `s' command

I have a text file that has many groupid = []. I wan't to edit the specific line which is 41, How can I do it? My command: sed -i "s/groupid = []/groupid = [ 2 ]/" rights.toml I have tried: ...
user avatar
  • 1
0 votes
1 answer
25 views

How do I use sed to replace with cat file content

I tried the following code, but it doesn't do what I want: echo "include(file.txt)" | sed -E 's/include\(([^)]+)\)/'$(cat $(readlink -f /tmp/$1))'/g' I need replace some special words with ...
user avatar
0 votes
2 answers
43 views

How do I get variable substitution to work with this sed command

I have this script: PATTERN=xAB dd if=/dev/zero count=1 bs=10 | sed "s/\x0/\${PATTERN}/g" > test_ab hexdump -C test_ab output I get is: $ ./make_test 1+0 records in 1+0 records out 10 ...
user avatar
  • 173
0 votes
1 answer
17 views

removing entire line with sed using wild characters

E219 E36 C5X C201 C19 C5X E229 E36 C5X E239 E36 C5X C311 C19 C5X In this file example, I need to remove all lines containing C[0-9][0-9][0-9]. How I can do this with sed command? The ...
user avatar
  • 284
0 votes
6 answers
176 views

delete 50 random rows in a txt files that have their second column labeled as 0

I want to use the terminal commands for deleting 50 random rows from a txt file that is tab separated and has these sample rows where the second column is 0. The value in the second column is either 0 ...
user avatar
  • 3,631
0 votes
3 answers
87 views

How to add quotes to second element of a string after comma in a text file bash

File contents: 1234,/Product/number 234567 2456,/Product/number 456789 and so on...many lines Want the the output as follows: 1234,"/Product/number 234567" 2456,"/Product/number 456789&...
user avatar
0 votes
1 answer
80 views

using sed command to give variables with echo

We are trying to use the sed command to give back contents from 2 files (file1q and file1a) - a question and answer file. The question and answer file are the same with numbers on each line: 1 2 3 4 ...
user avatar
0 votes
0 answers
22 views

How to compare two files interactively using sed and looping [duplicate]

We want to compare file1 (questions) to file2 (answers). File1: 1 2 3 File2: 1 2 3 Ask user: does "1" (from file1 line1) equal "1" (from file2 line1) ? User types YES or NO and ...
user avatar
0 votes
1 answer
22 views

Ubuntu Wordpress server tutorial error

I am going through the WordPress installation tutorial from Ubuntu Tutorials and I have typed this command as part of Step 6: sudo -u www-data sed -i ‘s/database_name_here/wordpress’ /srv/www/...
user avatar
0 votes
1 answer
48 views

sed and quotation marks

I get data files that contain both of these (with the commas and the quotation marks) ,"ncal", ,"NCAL", I want to replace all occurrences of ,"ncal", with ,"NCAL&...
user avatar
0 votes
2 answers
60 views

sed with ANSI color escapes fail

I do not know why this does not work: echo -e "$(echo "This is an uncolored text" | sed "s/{This is an uncolored text}/{This is an \033[0;34uncolored text\033[0m}/g")" ...
user avatar
0 votes
0 answers
57 views

sed command to replace start of a line with new line, but line includes " / caused sed output errors

I'm trying to replace the following line: <inet-address value="${bind.address:IP}"/> with a different line but I keep running into issues. There are similar lines up until the point ...
user avatar
0 votes
0 answers
65 views

Compare two lists, file1 and file2, get the IDs in file2 present in the usernames in file1

Please I need help... I have two lists, file1 and file2. The list file1 has only usernames, while file2 has the same usernames but with additional columns (username|private yes or no|id). Basically I ...
user avatar
  • 1
1 vote
1 answer
32 views

Appending text, written in variable, below current line using sed

I can append text below current line, using the sed editor: $ foo=bar $ echo "some text"|sed "a\bar" some text bar But when I try to append text from variable below current line, ...
user avatar
  • 1,476
4 votes
2 answers
797 views

Using sed with a variable inside double quote

I have a file input.xml which contains a line: <exciton lambda="1" fix="hole"/> in that line I want to replace 1 with 2 but I can't use just 1 as key word since there are ...
user avatar
0 votes
1 answer
37 views

Filter blocks of log-output from a log stream

Here's my task: I've got a source stream of live log output from a messaging process. Lots of output is irrelevant to me but there are sections i want to collect and evaluate separately. Those blocks ...
user avatar
  • 181
0 votes
0 answers
17 views

Updating Web Pages - Struggling with SED

I have a bunch of domains that I need to update, the structure is basically the same but the individual page names are different. Example: root-directory/review/ In the /review/ directory, there are ...
user avatar
3 votes
1 answer
194 views

Replace a text within single quotes with another string using sed(just a first occurrence of regex)

I have a file with the following content: $ cat file.txt CREATE COLLATION public.collation123 (provider = libc, locale = 'fr-FR'); CREATE COLLATION public.collation_1 (provider = libc, locale = 'bas'...
user avatar
0 votes
0 answers
32 views

Using sed or awk to remove near-duplicates

I currently use the following to get as close as I can do to a file cut -d ' ' -f 3- /var/log/issues.log | sed -E 's/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}//g' | sort -u So far it gets rid of ...
user avatar
  • 131
1 vote
1 answer
40 views

How to count the number of consecutive identical lines

I have a file that looks like this: 2000 2000 2001 2001 2001 2001 2002 2002 I need a script to show me this: 2000 - 2 2001 - 4 2002 - 2 I prefer using sed or awk
user avatar
  • 139
1 vote
1 answer
32 views

How to rename files: picture.jpg.~1~ to picture_~1~.jpg [duplicate]

I have say 30000 files of this type: picture.jpg.~12~ They are remnants of a backup (mv -v --backup=numbered ...). I needed to switch the extensions to: picture.~12~.jpg
user avatar
1 vote
1 answer
881 views

Apply sed operations only to lines beginning with a particular string

I have the following file format Received from +11231231234 at 2021-10-10T19:56:50-07:00: This is a message that contains words like from, at, etc. Sent to +11231231234 at 2021-10-11T06:50:57+00:00: ...
user avatar
  • 11
2 votes
2 answers
48 views

Command using sed

I have a problem. I want to change ole without changing dole in this file. I've tried to use: sed -i s/^ole$/kari/ file.txt Is there any way to change this without using two command lines as: sed -i ...
user avatar
1 vote
1 answer
103 views

Variables for constructing patterns for use with sed

I have written a bash function to print sections of text enclosed between lines matching ## mode: org and ## # End of org in a file, with an empty line between sections. Before the ##, there can be ...
user avatar
0 votes
1 answer
58 views

Find command from left to right and attach ID

I am trying to match MRI files with their volume files. Background: Link to files: https://wiki.cancerimagingarchive.net/pages/viewpage.action?pageId=68550661#68550661171ba531fc374829b21d3647e95f532c ...
user avatar
0 votes
2 answers
44 views

I need to insert 12spaces. It should match a particular string then go to next line with 12spaces

I have a file called space.txt. I am doing the string match with ath2. I need to insert a string "newdata" after 12 spaces. I tried the below command, which works, but used manual white 12 ...
user avatar
  • 11
1 vote
1 answer
285 views

How can I Pipe the output of FFMPEG 2 Levels of Piping in a bash script

I have been trying to pipe 2 levels deep. I can pipe successfully: ffmpeg | grep ffmpeg | sed I can not pipe ffmpeg | grep | sed ffmpeg | sed | grep I don't understand, does ffmpeg limit to only ...
user avatar
1 vote
1 answer
56 views

Making folders when the names have "/" and " ' "

I'm building up file paths (and mkdir-ing them) based on variables: mkdir "$root_folder/$title ($year)" I came across a situation where $title was 9/11: Inside the President's War Room. The ...
user avatar
  • 530
1 vote
1 answer
81 views

Sending bash script variables to sed

first time poster here and I searched for quite some time but didn't find a thread I could understand well enough to solve my problem. I have a loop in my script that generates certain variables via ...
user avatar
  • 13
0 votes
0 answers
19 views

Insert variables inside quotes [duplicate]

How insert variable inside quotes in this script? f=`sed -n '1p' < /path/ls.txt` I try something like this but it don't work.. f=`sed -n '"$i1"p' < /path/ls.txt`
user avatar
0 votes
1 answer
176 views

Why is renaming files with sed and mv printing '$'\r'

I am using Ubuntu on a Windows 10 machine. I am trying to rename 5 files (file1.txt, file2.txt, file3.txt, file4.txt, file5.txt) so that each file is replaced by Sample#_VoucherID.fastq.gz. To do this,...
user avatar
  • 27
-3 votes
2 answers
88 views

Extracting a row using sed

I was just wondering how would I extracted a specific row using sed?(My system has sed installed, so no awk unfortunately :( ). I got a text file like the following: Business Name,Description,Address,...
user avatar
-1 votes
1 answer
488 views

Using sed to extract specific columns

I was just wondering how would I extracted a specific column using sed?(My system has sed installed, so no awk unfortunately :( ). I got a text file like the following: Business Name,Description,...
user avatar
0 votes
1 answer
33 views

bash, display only in case output has count of n characters

how can I display content of output which has only count of n characters in second col divided by ,? For example, grep only line which content 4 characters in second col. Input. a,123 b,223 c,1234 d,...
user avatar
  • 776
0 votes
1 answer
84 views

Capture a string from JSON response

I have below Json response for POST method in bash and would like to capture value after sessionId":" and assign it to variable session_ID. {"changeId":"79911476-53a4-46e1-...
user avatar
  • 1
1 vote
2 answers
3k views

Sed for replace a substring inside a string with a pattern

I am trying to replace a part of a pattern, such as, if I have col(3,B,14), after applying the sed command, I would like to get col(3,B,t14) which adds the t character to the third parameter in the ...
user avatar
  • 21
1 vote
1 answer
60 views

Sed for replacing pattern

I would like to replace a pattern, which consist of a var surrounded by () with sed. The next command success : echo "This is the pattern : th_now(5, almost done!" | sed "s/th_now($var/...
user avatar
  • 21
2 votes
2 answers
840 views

How to write complex sed query which got special char

I am struggling to replace a string with a special character. I am using the command below and I tried to escape each special character, but I am still getting an error. If I don't use special ...
user avatar
2 votes
2 answers
623 views

Nested Command in sed substitution

I'm trying to used sed to find and encrypt ansible_password field in an inventory file and encrypt it with ansible-vault command. But ansible-command is failing throwing an sed error, where as a ...
user avatar
-1 votes
3 answers
1k views

How to change/remove the file extensions of a group of files

I have a bunch of .txt files in a directory, and I want to be able to find these files and strip the extension from the file name. I can find the files using: $ find . -maxdepth 1 -type f -name "*...
user avatar
  • 3,166
0 votes
1 answer
134 views

Weird output while using sed to rename files

I am using Ubuntu 20.04.2 with GNU sed version 4.7. I have a bunch of music files that got named weirdly because they did not have all the info I specified to be in the file name. For example, "...
user avatar
0 votes
1 answer
339 views

find: paths must precede expression: `.'find: possible unquoted pattern after predicate `-exec'?

i need to execute in background this command sudo find '/abc/abc/' -type f -exec sed 's/domain1\it/domain2\com/g' '{}' \; . & but I have two issues: find: paths must precede expression: `.' find: ...
user avatar
0 votes
3 answers
71 views

Batch Rename DIrectory Using Pattern Matches

I would like to change this directory structure to the one following it. Although another directory batch rename question exists, this one is quite different. l '001. Aretha Franklin - Respect.mp3'* '...
user avatar
0 votes
1 answer
59 views

How to fix problem with half outputs results

for f in 20*.txt do sed -n '1p' "$f" | cut -d' ' -f3 >> displayStudentInfo.txt head -3 "$f" | tail -2 >> displayStudentInfo.txt done cat ...
user avatar
1 vote
2 answers
819 views

Backslash missing in file while replace the string content using backslash contain variable

I want to write backslashes in a file, and I try to substitute some text with the value from a variable: $ TEST=\\etc\\hello $ echo $TEST \etc\hello But the backslash is missing when I tying to ...
user avatar
1 vote
1 answer
1k views

how to use grep and sed on adb logcat

I'm currently using grep in combination with adb logcat (android console api). Now I want to edit every line on the fly using sed in a pipe. However when using sed after grep the output becomes empty. ...
user avatar
  • 2,489

1
2 3 4 5
14