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

learn more… | top users | synonyms

0
votes
2answers
110 views

How to remove a script tag from a text file with sed

I have a number of header.php files that have a malicious script tag contained within them (don't ask). I've written a not-so-elegant shell script to replace these with blank space. I had initially ...
2
votes
2answers
34 views

Linux bash: Search and replace in file without escaping hassle

Is there any bash solution to do a simple "search and replace" without escaping hassle? I try to replace <!-- JavaScript --> in an html file with the content of a complex javascript file. I ...
2
votes
2answers
31 views

How to alter a column in a row in a tab delimited text file if it's duplicated

Lets say I have these many rows chr1 66999638 66999638 SGIP1 1 + chr1 66999251 66999251 SGIP1 1 + chr1 33545778 33549778 AZIN2 1 + chr1 8376144 8380144 ...
2
votes
2answers
61 views

Selective extraction of data

I have the following block of data in a txt file : Informatica(r) PMCMD, version [9.5.1 HotFix4], build [313.0217], SOLARIS 64-bit Copyright (c) Informatica Corporation 1994 - 2014 All Rights ...
0
votes
1answer
59 views

Using sed instead of grep to output only matching part of line

I am writing simple bash script (actually learning how to do it ) and i want this function to use just echo and sed and return exactly the same output. I found solutions with sed, they worked in ...
0
votes
2answers
25 views

How to loop on my files to find a file that have an exact expression at the beginning of a line?

I'm looking for a script that read all my files and find those which have int tube[2] written at the beginning of any line, I should use sed -e 's/Ancien/Nouveau/g' nomFichierEntrée > ...
2
votes
2answers
47 views

sed to match pattern between matching curly braces

From a pattern such as [string 1]{string 2} I want to extract string 2, the string between the last pair of matching curly braces -- that is delete [string 1] and the open { and close }. My ...
4
votes
2answers
64 views

BSD sed: Replace only the Nth occurrence of a pattern

Using BSD sed; How can I perform the following substitution?: Before: hello hello hello hello hello hello After: hello world hello hello hello hello In other words; how can I replace only the ...
1
vote
3answers
51 views

Remove first and last character if present

I need to remove the first two characters of every line in a file ( always the same ) and the last "/" if it is present. Input is, in the file F1 : ^./inst/oracle/ ^./tmp/ ^./inst/maj/ ^./mkcd ...
1
vote
3answers
73 views

Add line to configuration file from a bash script?

I am trying to figure out to locate a line in a configuration file, then to drop down two lines then to insert a line of code. I was attempting to do this in awk/sed but got stuck on the carriage ...
1
vote
2answers
71 views

Complex sed Command with AND/OR/NOT

I have a bunch of php files which have many select commands. In each query i want to insert a coloumn variable admin_id = '$admin_id' i.e. if the query is select * from users where abc='xyz' and ...
6
votes
4answers
218 views

CSV columnar reformat with SED (or anything other coreutil)

Given the following made-up segment from an output file from hashdeep: 7241,11111111111111111111111111111111,\01-data\file1 1237241,22222222222222222222222222222222,\01-data\file2 ...
0
votes
1answer
24 views

Replacing in files with sed using regex

i want to replace a string in many files like "Total:*points" using sed. I simply don't know how to use sed with regex. Below is what i got. Thank you in advance! find ./ -iname "skp-corr-*.txt" ...
1
vote
3answers
38 views

Transpose paramter values from a file and Generate parameter files from it

There's a file containing a table with the parameter names as the first line, values in the following lines: How to perform the following using awk, sed or any shell scripting utility: generate a ...
1
vote
1answer
48 views

substitute from beginning of line with 1 of multiple patterns to the end of another line with 2nd pattern

I have a file like this: data data data $globaltext blah gibberjabber somemorestuff etc ); data data data $otherjunk yada gibberish etc etc more etc ); My desired result is this file: data data ...
1
vote
3answers
71 views

Sed command with ' special character [closed]

I am trying to execute the following command from bash shell: sed -i "s/\(update.*\)where /\1 where primary_id = '$primary_id', /" *.php As you see, there is a variable which I am inserting using ...
5
votes
2answers
178 views

Command to remove the first N number of lines in input

Background I am running an SSH server and have this user that I want to delete. I cannot delete this user because he is currently running a few processes that I need to kill first. This is the ...
0
votes
1answer
23 views

Update phpmyadmin config.inc.php file in bash

When you download and extract latest phpMyAdmin, it comes with a config.sample.inc.php file. I would like to set a random blowfish_secret value on this line: $cfg['blowfish_secret'] = ''; /* YOU ...
6
votes
1answer
83 views

How to extract first base64 code out of file?

On Linux I'm having text files and each contains 1 or 2 base64 blocks of code. Following is part of the file and 1 base64 block. Content-Transfer-Encoding: base64 ...
3
votes
2answers
80 views

Merge and Append columns for more than 2 files

The files are tab separated. I have "N" number of files whose contents are as shown in the screenshot above. I want to merge them and append the 5th column. The first 4 columns are the same. I ...
1
vote
2answers
35 views

Return line conditonally on next line

I am trying to return a list of IP Addresses for computers that have a windows OS (for my security course). The output is in this format Nmap scan report for 192.168.xx.xxx Host is up (0.066s ...
1
vote
1answer
45 views

Use sed to retrieve variable from 1 file and place it in another

I need to use sed to retrieve a variable form within a file name. I am updating a previous code: cat /directory/filename1.xml | sed -e "s/XYZABC/${c}/g" > /directory/filename2.xml The value for ${c} ...
3
votes
5answers
109 views

split column after nth character

I'm trying to split my second column in the file below after every 4 characters. file.txt >1A THISISATEST >1B THATISATEST desired output: >1A THIS ISATEST >1B THAT ...
1
vote
1answer
47 views

Simulate sed read command with awk

I want to stimulate use of sed: sed '3r awk.scr' awk.script with awk.scr: a b c d e f and awk.script as: hello there is hello i'am there is hello sdfdf dfdfdf aads 23213 3 434 Using awk ...
1
vote
0answers
33 views

How to extract weather data from a html doc using linux string manipulation

I need to extract these info from this weather forecast site, but I don't know how much about string manipulation in linux: acm_RecentLocationsCarousel.push({name:"Irvine, CA", daypart:'day', ...
2
votes
2answers
58 views

How do I list all lines after two subsequent patterns are matched up to when they don't

I have files that are used to install files with specific owner:group and permissions. I'll ignore permissions for clarity and the details of installing files. Once an owner & group are set to a ...
1
vote
3answers
157 views

Read specified lines in file - BASH

I would like to read specified lines in file iptables. I want to read lines started with : and ends with space. File iptables # Generated by iptables 04:13:50 2015 *filter :INPUT ACCEPT [0:0] ...
2
votes
6answers
160 views

Use sed to find and keep only the lines with 2 alpha characters in them

I have a file with many lines like these 33B87401 33B87402 33B87403 33B8EE44 33B87405 33B87406 33B87407 33B87408 33B87409 33B8740A 33B8740B 33B8740C 33B87D0D 33B8740E 33B8740F 33B87410 33B87411 ...
1
vote
2answers
24 views

sed to match zero or more number of spaces in a string

function getVal { sedPattern='s/^.*"keyVal":"\([^"]*\)".*$/\1/' finalSedPattern=${sedPattern/keyVal/$2} echo $(sed $finalSedPattern <<< $1) } This is my Json parser written using ...
4
votes
4answers
111 views

Extracting strings from between special characters

I have a large text file created from combining lots of html files. cat *.html > all_html_files.txt Inside the text file are specfic strings that I want to extract to another text file. For ...
4
votes
1answer
114 views

In POSIX sed, does the period (dot) match a newline in a multiline pattern space?

In GNU sed it works. For example, this matches two blank lines in a multiline pattern space (created with N) /^\n$/ Is this standard?
3
votes
2answers
112 views

need to replace a file contents

I am stuck in a situation. I have a file script.txt with contents $cat script.txt SET TABLESPACE CONTAINERS FOR 3 -- IGNORE ROLLFORWARD CONTAINER OPERATIONS USING ( FILE ...
6
votes
2answers
412 views

Why does [0-9]* match where there aren't any digits?

so the command is : echo "abc 123" | sed "s/[0-9]*/h/g" and im getting output as hahbhch h how am i getting this output? the output i expected it to be is abc h which im getting by ...
10
votes
8answers
287 views

sed in-place line deletion on full filesystem?

Due to an application bug as yet undiagnosed, I have several hundred servers with a full disk. There is one file that has been filled up with duplicate lines—not a log file, but a user environment ...
5
votes
7answers
294 views

Remove lines from tab-delimited file with missing values

I have a large (~900MB) tab-delimited text file that I will be processing in a downstream program. I need to delete any line with a missing value. The correct number of columns are on each line (so ...
-1
votes
1answer
64 views

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

I try to use sed command inside a loop to replace IP address, but it is always giving me this error: sed: -e expression #1, char 15: unterminateds' command` even it is not missing the end slash. ...
3
votes
2answers
24 views

vi — replace chars from part of line

I've got a file with all Belgian cities. Some of these cities have boroughs. Lier;stad;Antwerpen;49,70;33930;Lier;Koningshooikt ...
0
votes
1answer
28 views

Use sed to edit a line in a file with spaces in the name [duplicate]

I am looping through folders, opening a file within the folder with the same name, and doing some manipulation. I'm using sed to manipulate a line: sed "1s/Log R Ratio/$SAMPLE.LRR/" $FILE where ...
1
vote
1answer
41 views

Don't run this sed when a string is matched?

I have this sed command for deleting numbers inside of tags: sed 's/\(<[^0-9>]*\)[0-9]*\([^0-9]*>\)/\1\2/g' But does anyone know how I can exclude certain strings from this? Now it would ...
3
votes
2answers
57 views

Replace only on the first matching line with sed

Using BSD sed (no GNU extensions), how can I perform an operation similar to the example provided below, but where instead of the line number, the replacement is performed on the first line in which a ...
0
votes
2answers
42 views

Remove both lines if column A values are repeated in next row

My input is like this: pak_c35079_g1_i1|m.14890 Pfam pak_c20797_g1_i1|m.3458 ProDom pak_c20797_g1_i1|m.3458 Pfam pak_c28265_g1_i3|m.9595 TIGRFAM pak_c28265_g1_i3|m.9595 ...
1
vote
1answer
70 views

sed returns the following error sed: -e expression #1, char 101: unknown option to `s' [duplicate]

I'm writing a script to replace a label <p> with a path in some text files (*.prop). However , when I run it I get the following error: sed: -e expression #1, char 101: unknown option to `s' ...
1
vote
1answer
45 views

Remove leading 0 from specific field

I have a file with multiple fields but only want to remove the leading 0s from the 2nd column (col B) rather than all of the columns. I have tried: sed 's/^0//g' filename > new_filename but this ...
2
votes
5answers
40 views

Help on edit a sed statement

I'm writing a script to change on the fly the firefox home page through a text variable: sed -i 's|\("browser.startup.homepage",\) "\(.*\)"|\1 "$ddrs"|' /home/max/.mozilla/firefox/*.default/prefs.js ...
1
vote
2answers
54 views

Linux convert a number into a string on the 6th column

I created a script that extracts data from a database and loads it to a csv file. I am using SunOS hstz1454 5.10 system. Is there a way I can translate/convert a number to a string on my csv file. So ...
2
votes
2answers
209 views

Solaris using sequence generator at the beginning of each new line

I am new to shell scripting. I created a script that extracts data from a database and loads it to a csv file. I am using SunOS hstz1454 5.10 system. I am trying to do a sequence at the beginning of ...
4
votes
2answers
136 views

concatenate n lines with sed

Recently, I asked a question how to sort pairs of lines, and one of the answers suggested concatenating lines with sed, like this: cat file.txt | sed -n 'N;s/\n//;p' | sort -t";" -k43,43n | perl ...
0
votes
1answer
30 views

In bash I'm unable to concatenate a string using a variable defined from output of echo + sed

I'm trying to concatenate a string with $result. Placing another string BEFORE $result results in the two strings not being concatenated: ...
3
votes
1answer
203 views

Using SED to cut after 7th character of each line

Just trying to cut any characters after the 7th on each line of a text. I initially tried this: sed 's/(.{7}).*/\1/' TestText.txt But got this response: sed: 1: "s/(.{7}).*/\1/": \1 not defined ...
0
votes
4answers
71 views

Why isnt this simple grep/sed script working [closed]

I have a variable with, among others, a line that looks like this iBMC=277 I'm trying to match that like this: BMC="$(echo "$allnow" | grep iBMC=[0-9] | sed 's/iBMC=//g')" This makes BMC empty. ...