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 is a command-line stream editor for filtering and transforming text.

0
votes
2answers
26 views

Print only the lines that with all digits except the last one or the last two characters or the first or second characters

I have a big text file has lines with all numbers and with all letters and characters and also has lines mixed with numbers , letters and characters i want to print only the lines that have all ...
-6
votes
1answer
31 views

Delete lines between two pattern when a pattern is found/not between them [on hold]

I have a xml file which contains data that needs to splitted into two files based name tag "XXXX" eg: FILE A <abc> <def> <Control name link="N" adddress="10000"> <...
0
votes
1answer
36 views

Replacing cronjob schedule using sed

I want to replace 9 3 * * 3,6 by shivam using sed command. testcron is the file name. I am trying this sed 's/"9 3 * * 3,6"/shivam testcron NOTE: testcron is the file name.
-1
votes
1answer
40 views

How can I replace ~60 print entries in 5 different files using vim or sed?

Fabfile (directory) containing Python files: print "DEBUG fab_helper DRYRUN: True"+var print "DEBUG fab_helper DRYRUN: True" #print "DEBUG cfn_stackname: "+cfn_stackname To: LOGGER.DEBUG("DEBUG ...
0
votes
0answers
22 views

sed multiply a number in an xml-attribute by factor of ten

I would like to multiply the attribute in viewBox of svg-files by a factor of ten. I want to change <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" version="1.1"> to <svg xmlns=...
4
votes
2answers
142 views

sed or awk: remove numbers after a symbol

I would like to remove just the numbers and "_" after ">" symbol, for example: >1_CR-B_CR56_t MTKIIKFVYFMTIFISPNHHCPVYNCTHPKQPWCKLVRLQLLFHGSLIGLCDCI >2_R-B_R46_t ...
3
votes
2answers
89 views

Sed replace word except when word is preceded by a specific string

I want to replace all instance of abc with 123 provided it isn't preceded by https://. Code: file=Data.txt Initial="# Start"; orig="abc"; new="123"; Final="$" # Line Number sed -r -e "/${Initial}/...
0
votes
1answer
62 views

How to strip out white space of a filename

Opering System : RHEL 7 Bash Script: V_No=10.8.3 BUILD_VERSION=`echo ${V_No} | tr ' ' '_'` echo "File Name: Dev-${BUILD_VERSION}.jar" output: File Name: Dev-10.8.3 .jar expected output: File ...
-1
votes
1answer
25 views

Finding and replacing text when there are custom elements within [duplicate]

I have about 450 html files I need to edit. I have the directory they all are in, so that narrows things down from the perspective of searching. What needs to be changed is a bit of known text, some ...
0
votes
2answers
41 views

Add new lines above each existing line in a file

I have a file with below lines This is an PLUTO This is PINEAPPLE This is ORANGE This is RICE How do I make a new line above each lines and insert the last string to the new line output as below: ...
0
votes
1answer
58 views

Sed Replace a pattern between a pattern and the end of file

From SED: insert text after the last line? - Unix & Linux Stack Exchange, I learnt that $ if used outside the substitution in sed represents the end of file. This I have tried to use in the ...
-1
votes
0answers
25 views

Bash grep with date comparison

So, I have basically automated a majority of client license expiration reports and license renewals for our clients (I grep files for 31-dec-2018 and then echo the information into a text file that ...
1
vote
2answers
62 views

convert tab delimited data to , delimited records with double quoted fields “ ” [on hold]

I want to convert tab delimited csv into " ", add empty space if value is empty FirstName LastName Address1 Address2 City State ZIP John1 ...
0
votes
1answer
38 views

Unix - replace filenames with unique prefixes in a directory with specific unique prefixes from a file in the same directory

I have hundreds of files in a directory with the same suffix and unique alphanumeric prefixes like this: ABC01234.sorted_dup.bam ABC04271.sorted_dup.bam ABC09287.sorted_dup.bam I have a file with ...
-3
votes
1answer
19 views

Comparing two fields from two files and printing the common items from the files with the count from each file

I have two files in a below-mentioned way File1 Emp1 Dec10 12Am Emp2 Dec10 2Am Emp3 Dec10 4Am Emp2 Dec10 6Am Emp1 Dec10 8Am File2 Emp1 Dec11 12Pm Emp2 Dec11 2Am Emp1 Dec11 3Am Emp3 Dec11 ...
4
votes
3answers
332 views

Manipulating text in first column only? [duplicate]

Example Input: foobar@example.com foo@example.com,bar@example.com Example Output: foobar@example.org foo@example.com,bar@example.com So, in "normal" circumstances, it would obviously be easy to do ...
0
votes
2answers
42 views

Gnu Sed: Space Character class not matching for end of line character

Pattern: abc followed by space or is the last character in a line. orig="abc[[:space:]]+"; new=Hello sed -i -r -e "s|${orig}|${new}|g" ./file ; File: abc abcd abc abc d After executing: abc abcd ...
0
votes
2answers
45 views

Search and replace specific tag value in XML file with sed command

I have a task where by I have to manipulate an XML file through a bash shell script. Here are the steps: Query XML file for a value. Replace the value of a different element with the new value. ...
1
vote
1answer
28 views

How can I insert a character in a string?

I have tried echo "ABCDE-123456" | sed 's/-//' | sed 's/./& -/g' A -B -C -D -E -1 -2 -3 -4 -5 -6 - sed is not putting the - on the first character. How can I make ...
-1
votes
0answers
28 views

sed - prepend file name to each line, variable expansion [duplicate]

I cannot figure out the variable expansion for sed. I've tried many possible combinations of single/double quotes, but either it takes the variable as literal or I get "unknown option to 's". I am ...
0
votes
2answers
36 views

replace a string from a specified line number and column

I would like to replace from line number 4, the character "K" which is right after 19823 but not the "K" character which follows 19822SOL OW60021 7.173 19822SOL HW160022 7.230 ...
0
votes
0answers
26 views

while read loop seems to terminate after the first line, when using two pipes?

#!/usr/bin/env bash set -euo pipefail while read -r line do echo "line via echo:" echo "$line" echo "line via sed:" sed 's/w/f/g' | sed 's/f/zzzzz/g' <<< "$line" done < /dev/...
1
vote
2answers
95 views

How to replace a string when another string is found in a line?

I want to replace a string 'xy' with another string 'ab' when string 'ny' is found in a line of a unix file. Sample text: If we have xy today we can go to ny. If we have xy tomorrow we can go to ny ...
1
vote
4answers
64 views

replace a string with sed from specific lines

I do know how to replace a string from a specific line such as: sed -i "<line number>s/<old string>/<new string>/g" <file name> however I do not know how to replace a string ...
2
votes
2answers
113 views

How to break line after matching case but needs to go back a couple of characters

I have the following sample: 1. TNT 00:00 2. Swing From The Gutters 7:34 3. Ten-Day Interval 13:29 4. I Set My Face To The Hillside 18:16 5. The Equator 24:26 6. A Simple Way To Go Faster Than Light ...
2
votes
1answer
108 views

Bash string range and replace

To print part of the string, replace , with . I use command: echo "${q:16:6}" | sed 's/,/./' Is it possible to use something like: echo "${q:16:6/,/.}" because it does not work?
1
vote
2answers
28 views

Filter unique data from text file based on specific columns without sorting

I have various text files with between 10-100k lines following the format below. "2018-12-07 23:21:32",XX,99,ZZZ,250,REMOVED "2018-12-07 23:25:17",XX,99,ZZZ,250,AVAILBLE "2018-12-07 23:29:05",DD,11,...
0
votes
0answers
31 views

Parsing CSV that has multiple line values with carriage returns

I have a CSV that I'm trying to remove the double quote values from using the following sed one-liner. Details about this can be found in my original post to figure that out sed -i.bak 's/^"//g;s/","/...
0
votes
2answers
61 views

Modifying individual text fields in bash script

I have this variable whose length should always be 9 characters PEPTIDE_SEQ="AAAAAAAAA" Then i created the length variable as len=9 What i want to do is to start from the PEPTIDE_SEQ and output ...
2
votes
2answers
46 views

Extract all line from a file that contains two strings in any position [duplicate]

I have a .txt file with contents similar to this: 100 150 180 200 300 400 100 200 250 350 380 400 100 160 170 400 450 500 100 120 140 160 180 200 100 120 140 160 180 300 I want to grab all the lines,...
0
votes
1answer
23 views

shell script /unix commands for text file content editing [duplicate]

I want to edit the file contents in the 2nd line and 2nd column ,which is a file name from that I want to remove the part after the last underscore and before the file extension . The contents of the ...
1
vote
5answers
73 views

Remove text between consecutive occurences of strings

I need to remove all text between two given strings in a text file. The strings may be located on different lines. For instance, in the following text file @article{ginsberg_lifespan_2018, title =...
-1
votes
3answers
28 views

replace multiple strings in a file in python3 [closed]

I have test file where i have some entries like below and i need to change memberUid to nisNetgroupTriple along with the names $ cat testfile2 memberUid: tony memberUid: jacob memberUid: zenny ...
0
votes
2answers
49 views

Want to edit a file content for Removing the string after the last underscore and before the file extension using Unix commands

I want to edit the file contents in the 2nd row and 2nd column ,which is a file name from that I want to remove the part after the last underscore and before the file extension . The contents of the ...
0
votes
0answers
25 views

How to remove all comments from a javascript file using common Linux command line tools?

I have a javascript file with deeply needed comments. Javascript uses C style comments: //this is a single line comment And /* this is a multi-line comment */ However, the actual code looks ...
0
votes
2answers
63 views

SED not removing last double quote from every line

I have a CSV that was exported with double quotes around every header and value and I need them gone but without removing double quotes that might actually exist as values. For example: "HEADER1","...
-2
votes
3answers
41 views

sed/awk string replacement with newline and tabs

I have an XML file that contains the following: <ipaddr>192.168.1.1</ipaddr> <subnet>24</subnet> The goal is to modify <ipaddr>192.168.1.1</ipaddr> to <...
-1
votes
2answers
44 views

How to trim the spaces from first and last of the variable string in Linux? [closed]

I am trying to remove white spaces from each variable string. I tried with below command but no use. a="HARISH , SAM" echo $a|sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'
1
vote
1answer
39 views

Ask sed to ignore all special characters [duplicate]

I use the following code to delete a line : sed -i "0,/$DELETE_THIS/{/$DELETE_THIS/d;}" file.txt But this code fails if the variable DELETE_THIS contains special characters, like ., /, * and so on......
0
votes
1answer
43 views

Regular expression used in sed not giving the desired result between intervals [duplicate]

I am using the sed command to get the data between 2 dates. I am using regular expression matching the pattern for the dates. The sample data I am using is somewhat like: 192.168.0.123 - - [25/Nov/...
1
vote
3answers
56 views

Sorting filenames uniquely

I have searched for the solution but couldn't find answer to my problem. I have thousands of file in a directory. Filenames are in the below format 74687_1543944930857.txt 74687_1543945090451.txt ...
0
votes
3answers
35 views

remove last number from string

I have a file test.txt, below the content: SCDE1 SF9 STR1D2 SREDF21 FRED STER2R4 I want to remove only the last character if it is the number, so the output should as below: SCDE SF STR1D SREDF2 ...
0
votes
1answer
23 views

Use sed to prefix and suffix multiple strings per line

I have a .sql file with some 15,000,000 INSERT commands on each line, which look something like this: INSERT INTO tableName (col1,col2,col3,col4,col5,col6,col7,col8) VALUES ('Jan 7 2018 12:33PM', 'R'...
0
votes
1answer
11 views

replacement of a string in xml

I am trying to replace folder name value in an xml file.I am searching with required pattern using grep and replace the folder name value which is DF_GCSS with ABC_DEF which comes from a variable....
0
votes
1answer
27 views

sed command not giving proper output for regular expression used

I am trying to fetch data between a range of time intervals from the log file. However, the complete data is not fetched for the end date. Below is the command used: sed -n '/26/Nov/2018/,/30/Nov/...
0
votes
1answer
17 views

Sed - Find and Replace “..\” with “..\..\” - AKA Down 2 Levels

I'm trying to replace ..\ with ..\..\. (I moved a folder and need to manipulate file paths in an xml.) I finally got my command to go without errors, but didn't get the result I wanted, can anybody ...
1
vote
0answers
27 views

Cutting output from sudo in a bash script

I am writing a script that is supposed to ask for user's password, do some stuff with it and eventually pass it to sudo. This is roughly how it looks: echo "input password: " read -s password printf "...
0
votes
1answer
19 views

How to replace an entire paragraph in a file?

I want to change this: ... %%%23begin aaaaaaa \\ bbbbbbb \\ ccccccc \\ %%%23end ... to this ... %%%23begin xxxxxxxx \\ yyyyyyyy \\ zzzzzzzzz \\ tttttttt \\ %%%23end ... the number ...
2
votes
1answer
79 views

How to retrieve counts of IP addresses from log file?

I am checking a log file to retrieve ip adresses plus how many times a log failed. This is what my log file looks like: Feb 2 15:20:02 tank sshd[14870]: Failed password for root from 143.100.67.173 ...
0
votes
0answers
57 views

sed: 1: “10.10.10.10/11.11.11.11/g”: invalid command code

I want to create a script which will changes all the occurrences of IP to a new IP in a current folder. my idea is to search for IP and replace it with new IP with sed. here is my sample code to ...