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

learn more… | top users | synonyms

0
votes
1answer
16 views

sed: -e expression #1, char 4: unknown command:

Could someone tell me what does this reply mean ? sed: -e expression #1, char 4: unknown command: ` ' I get it when I use : sed -n "$num"p $javaFile >> ~/Desktop/$1_sql.txt for i in `seq 5 ...
2
votes
2answers
29 views

Help with iterating fieldA in CSV file, where fieldB has specified value

I've been trying to setup a script to run on gitbash, to process a CSV file so each record that has a specific value, the last field is changed from empty ("") to a value that iterates from 1 to 16. ...
3
votes
2answers
75 views

convert C style comments to C++ style using sed

I'm trying to convert single line 'C' style comments to 'C++' style. The 'sed' below isn't bad, but of course it fails if any leading code (code before the comment) has any ' / ' in it at all: sed ...
0
votes
1answer
24 views

How do I extract information with what I have right now?

I have a bunch of swfs, these swfs include links to other swfs inside them. I use this to convert them to xml: swf2xml Disc1.swf Disc1.swf.xml. Then I use this to remove every single line that does ...
0
votes
1answer
36 views

Read line from file, manipulate, and then append to another file

To pool specific content from a batch of files, I do for ID in {92..128}; do sed '3q;d' directory_$ID/stats done Now what if want to put the $ID in front of each line read (preferably shifting ...
5
votes
4answers
206 views

Replace a string containing newline characters

With the bash shell, in a file with rows like the following ones first "line" <second>line and so on I would like to replace one or more occurrences of "line"\n<second> with other ...
0
votes
0answers
48 views

Sometimes command with many pipes makes empty output [on hold]

I am wondering what causes this problem and finding the solution (except for temporary file). When I execute certain code CHIMP+testis_uniq_expression.out file with like this, it makes empty output. ...
1
vote
2answers
64 views

Print a line in stdout that matches an expression if the output contains another expression

This might be a common/easy task but I couldn't figure out from examples on the web or manuals of awk/sed/grep. So, here is the scenario: There is an internal command line tool that prints out a ...
-2
votes
0answers
15 views

Uniqe values in a table [duplicate]

I have asked this question before but later on I realized that the answer provided by @Anthon is not working properly for me How can I find unique values in two a column table? Let me again define ...
0
votes
0answers
21 views

to check fields in configuration file

i have configuration file in which first field is filename, second field is the column if we find the value of that column is null in the filename that is given in first column. if any of value of ...
1
vote
3answers
42 views

How to List files which contain white space in filename? [duplicate]

I am trying to read files one by one by using the for loop like below, by passing argument to the functions. Argument 3 makes lot of problem due to space in file names. Example: ...
2
votes
1answer
37 views

How to replace the first line using sed?

Hi i am trying to replace the header line from my file using the sed command as mentioned below, sed "1s/.*/$new_header/" Test_file.csv The above line replaces the header and prints in stdout , ...
1
vote
4answers
119 views

Sed/awk/perl: reversing order of comma separated values, preserving other text

I have this text: LABEL1 .BYTE 01, 02, 03, 04, 05 .BYTE 01, 02, 03 I need to reverse only comma separated values order: LABEL1 .BYTE 05, 04, 03, 02, 01 .BYTE 03, 02, 01 I need ...
1
vote
1answer
48 views

count matches and mismatches group by

Please help with a shell script of the following. I need count number of consistent variables in each lane (col1) across samples (col2). For example, since all the values (col4) of lane1 variable 1 ...
2
votes
2answers
39 views

Sed/awk/perl: modify text preserving parts and align to a column

I have a text like this: A1JOURNEY0TO1 .BYTE 00, 00, 00 A2JOURNEY0TO2 .BYTE 00, 01, 00 A3JOURNEY1TO0 .BYTE 00, 01, 01 I need to have: JOURNEY_01 ; 00 TO ...
-1
votes
1answer
66 views

Regular expression to mask credit card digits in a file

What is the most simplest way to mask all numbers but the last 4 digits of a credit card number in a file using sed. Using egrep with the following regular expression we can find numbers of Visa, ...
6
votes
5answers
162 views

sed - remove the very last occurance of a string (a comma) in a file?

I have a very large csv file. How would you remove the very last , with sed (or similar) ? ... [11911,0,"BUILDER","2014-10-15","BUILDER",0,0], [11912,0,"BUILDER","2014-10-15","BUILDER",0,0], ...
0
votes
1answer
31 views

How to replace symbol || with |“”| using sed

I have a file that uses | as a delimiter. Some of the records have empty cell as || (nothing inside). I am trying to replace them with |""| with following sed command: sed -i 's/\|\|/\|""|/g' file ...
2
votes
1answer
31 views

sed lines after match and before next match

How to get all the lines after a matching word till the next different matching word? For example, my input looks like below. 1 2 3 5 6 and I need to sed from 1 to 5 and in my output I need to ...
0
votes
0answers
25 views

Find & replace image URLs in one file from another file

I am trying to replace all the image source URLs in an HTML file from a list of URLs in a text file. File1.html <td class="MetadataRes" width="380px" colspan="2" style="border-top: 1px #336699 ...
0
votes
1answer
79 views

Extract values from filename and add it into a text file

I have a gridded model data (separated by different depth) saved in text files. The structure is like this: Format of every column in a row in the text file: x_coordinate y_coordinate density ...
0
votes
1answer
28 views

Another unterminated 's' command

I am trying to make a simple replacement for an IPv4 address script. sed "s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/192.100.100.100/g" This is what I have. As stated in the title I ...
1
vote
1answer
45 views

Rename file using sed

I have files whose filenames are in format ddmmyyyyTEXT.txt I want to rename all the files to yyyy-mm-dd-TEXT.txt Here, TEXT is some arbitrary text. What sed expression I should use ??
0
votes
3answers
46 views

Filtering a .CSV file based on consecutive numbers in a line

I have a CSV file as follows: 1st 2nd 3rd 4th ID ... Res Res Res Res (other columns) ... RZ_AUTO_1, 1cx0, C118, B, C119, B, A165, ...
3
votes
2answers
88 views

How to add new lines from another file with sed

I'm trying to find the sed command so that I can put filename into filename1. These are my two separate files. INPUT filename has: Cindy 11 22 54 Chester 48 12 84 INPUT filename1 has: Name ...
1
vote
3answers
91 views

“bad flag in substitute command: '{” while replacing a string with sed from one file to another file

I am trying to replace strings found in File1 with strings in File2 File1 <IMG SRC="/Repository/GetImage.dll?baseHref=Orange/2011/03/27&amp;EntityID=Ad12911&amp;imgExtension=" /> ...
-1
votes
1answer
38 views

How to remove only 0-9 character long numbers from a file?

How can we remove only the numbers that are 0,1,2,3,4,5,6,7,8,9 character long from a file? I mean the lines that are matching this pattern. Example for removable lines: cat input.txt 1 123423113 ...
0
votes
1answer
57 views

Cut a specific part of a column from a csv file [closed]

I have to process a csv containing about 15 columns one of which contains a particular timestamp that includes milliseconds. When I go to insert this csv into a DB, I get an error because of this ...
1
vote
2answers
29 views

extract certain string, search and replace or keep a longer string contain the extracted value

The input file that needs to be edited is as below (can have more rows): bundle_id target_id length eff_length tot_counts uniq_counts est_counts eff_counts ambig_distr_alpha ...
2
votes
4answers
71 views

replace several comma out side one or more sets of curly braces and exception that in one or more sets of curly braces

In the text file I have multi records. Every record has multi column with comma separated, some column have one sets of curly brace and other have more than one curly brace. I need: If a comma is ...
2
votes
1answer
75 views

Sed to Modfiy Hosts File

I have a text file, modifyhostslist.txt, which contains entries that correspond to entries found in my hosts file. Not every entry in my hosts file needs to be modified, only entries also found in ...
2
votes
4answers
62 views

How to remove part of a string

I keep reading the sed documentation and lots of posts but can't seem to figure this out. I have a large number of Java files. In those files are calls to a method that take the enumeration converted ...
-1
votes
2answers
70 views

Edit a file in /etc using shell scripting?

How do I use sed to edit the file /etc/heat/heat.conf? I want to add the new lines under the default section [DEFAULT] rabbit_host =controller rabbit_password =RABBIT_PASS
-4
votes
1answer
43 views

How to use Sed to replace all characters in between colons

How to replace all characters between colons using sed? # replace easy with 123 sed:easy:abc -> sed:123:abc # replace hardest with 123 sed:hardest:efg -> sed:123:efg # replace magnificent ...
1
vote
3answers
130 views

keep only certain part of a string in a certain column

I have a file like this: id target_id length eff_length 1 intron_FBgn0000721:20_FBgn0000721:18 1136 243.944268 1 intron_FBgn0000721:19_FBgn0000721:18 1122 ...
1
vote
1answer
57 views

Replace pattern in file with pattern in second file

I want to replace part of a file's data, with data from another file. Suppose file1 has data as is written below and file2 has some data I want to store and replace file1 data from file2 from ...
2
votes
2answers
23 views

Match from current line until a line that doesn't match a pattern

I really tried searching but could not find anything (it's hard to know what exactly to search for). I know how to do this with sed: print from current line until the line that matches SOMETHING: ...
1
vote
1answer
43 views

Replace new lines char (^M) in all files and then rename file based on char string

I am not a UNIX guy but understand enough to gin up small scripts here and there except for this one where I may personally be not able to devote enough time. I have about 2000 files in a directory ...
2
votes
1answer
68 views

How to remove specific lines from a file?

I have a file (ip.txt) that contains ip rules /sbin/iptables -A INPUT -p tcp -s 140.237.4.252 -j DROP /sbin/iptables -A INPUT -p tcp -s 143.227.5.22 -j DROP /sbin/iptables -A INPUT -p udp -s ...
5
votes
2answers
180 views

sed + how to delete the second character “.” from the line

how to delete the second character "." from the line what I have is this ( but its remove the first "." from output uname -r | sed s'/\./ /' 2 6.18-164.2.1.el5PAE while I need the following ...
4
votes
2answers
52 views

How to exchange words in a filename using the shell?

One of my customers is a school. On their file server all projects have a directory with the same naming scheme. <last name>, <first name> <second name>? - <project ...
-1
votes
2answers
47 views

Using 'sed' to find and replace [duplicate]

I know this question has probably been answered before. I have seen many threads about this in various places, but the answers are usually hard to extract for me. I am looking for help with an ...
5
votes
7answers
411 views

Decoding URL encoding (percent encoding)

I want to decode URL encoding, is there any built-in tool for doing this or could anyone provide me with a sed code that will do this? I did search a bit through unix.stackexchange.com and on the ...
1
vote
1answer
67 views

Sed: replace particular one/two digit(s)

I have data in a table. And in one column I need to replace some indices (numbers from 1 to 23) to 3-4 digits sample numbers like: 2347,3856 etc. So the original column looks like: SF=1,2 SF=12,7 ...
2
votes
3answers
100 views

Call sed to replace a string stored in a bash variable

I want to expand a variable in bash with sed or awk. This variable is an array. For example, the script must delete strings contained in array. I tried ARRAY1=( string1 string2 string3 ) sed -i ...
1
vote
3answers
119 views

sed + find value before word in line

How can I find the value before the word "free"? top -n1 | grep Mem Mem: 2054968k av, 2034120k used, 20848k free, 0k shrd, 186768k buff First I tried top -n1 | grep ...
-2
votes
1answer
48 views

Extract/print every 3rd occurence of pattern

I need help with extracting/printing lines until a stop pattern. This needs to happen after every 3rd occurrence of start pattern, i.e ERROR_FILE_NOT_FOUND and continue until the end of the file. ...
2
votes
1answer
92 views

grep search expression and rename file

I have readable pdf files that all contain the string VAX followed by eight numbers, like VAX00002885. Now I want to find that expression and rename the corresponding pdf to VAX00002885.pdf (in this ...
1
vote
2answers
30 views

char-to-char substituion with sed

I am trying to make a monoalphabetic substitution decoder in bash: I have a set of characters that form an alternative alphabet like real alphabet -> ABCDE ... my alphabet -> DGHJK ... I ...
0
votes
1answer
28 views

Replace copyrights recursively [duplicate]

I have many files under the current directory. Each file contains copyrights headers like, # # Copyright 2013 Company, Inc. All rights reserved. This software # is property of Company, ...