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

learn more… | top users | synonyms

1
vote
2answers
37 views

Formatting a floating point variable in a SED statement

As part of a makefile recipe, I want to repeatedly adjust a few lines in some text file txt.in. In particular, I want to update, among others, the third line which contains simply two numbers ...
0
votes
2answers
45 views

Fastest & Most Core way to replace “\r\n” with “\n” in a file?

I suppose tr is a more core method and thus probably a faster way to replace things within a given file. However tr can only replace equal amounts of characters. meaning... 2 characters can only be ...
0
votes
4answers
52 views

More concise methods for wrapping a file than using sed

Introduction script: sed -i '1i <?xml version=\"1.0\" encoding=\"utf-8\"?>' $1 sed -i '/<?xml version=\"1.0\" encoding=\"utf-8\"?>/a<hello>\n\t<world>' $1 sed -i ...
4
votes
4answers
151 views

How to get lines 10 to 100 from a 200 line file into a new file [duplicate]

I have file with 200 lines. I need to extract lines from 10 to 100 and put them into a new file. How do you do this in unix/Linux? What are the possible commands you could use?
-1
votes
0answers
19 views

replace $ with £ using sed command [duplicate]

I have text file DollarToPound.txt with some Dollar signs ($) please provide a shell script to replace dollar symbol with Pound(£) with sed command. iam getting command garbled error!!! please help. ...
-2
votes
3answers
114 views

Replace $ with £ using sed command

I have text file DollarToPound.txt with some Dollar signs ($). Please provide a shell script to replace dollar symbol with Pound (£) with sed command. I am getting: batch@BATCH:[~/output]$ ./del.sh ...
1
vote
3answers
55 views

multiplication of every line

I would like to calculate a value on every line of a file such as this: 1 1441792,11534336 2 1048576,8388608 3 1441792,1153433 4 1966080,15728640 5 393216,3145728 6 2621440,20971520 7 ...
0
votes
2answers
43 views

awk to Read between two Particular Strings and discard the rest

I'm using awk to just read text between two strings "Check" and "Result". I've used many variations of it found on the internet and still can't get the favored result. I've tried: awk ...
0
votes
1answer
27 views

Creating a file from another file on the basis of a numeric value in each line

We will generate a csv file with below values. yp1234,577,1,3 yp5678,570,3,5 yp9012,132,8,9 I need to extract data and create files based on second column. If it's value greater than 577 then the ...
3
votes
3answers
154 views

Replace multiple strings in a single pass

I'm looking for a way to replace placeholder strings in a template file with concrete values, with common Unix tools (bash, sed, awk, maybe perl). It is important that the replacement is done in a ...
2
votes
5answers
121 views

Using sed with special characters

I have a directory full of XML files that look like this, for which I want to change the value of the "offset" element number from 1 to some other number $ cat my.xml <offset ...
0
votes
2answers
13 views

Finding and replacing text inside awk block

I want to find and replace a value inside awk block. Here is a sample input file to my script P1 10,9:11/18013013582 ,10:1 ,167:0 ,487:5/E.164 11,9:15/310410532169026 ,10:60 ,167:0 ,487:4/IMSI ...
6
votes
8answers
560 views

Grep rest of line…after match

I have a file containing only two lines, with the following structure: $ cat /tmp/pwpower.log 000D6F0000D34227, -114.10 000D6F0001A405C4, -130.09 The values are power values of my solar plant. ...
13
votes
6answers
562 views

Replace string containing newline in huge file

Anyone know of a non-line-based tool to "binary" search/replace strings in a somewhat memory-efficient way? See this question too. I have a +2GB text file that I would like to process similar to what ...
3
votes
4answers
77 views

Use the sed command to search text file for entries 10000 and under

I'm trying to use the sed command to search a file for all entries 10000 and under but I think this incomplete sed search string might be for entries 10000 and over: sed -n ...
1
vote
1answer
33 views

Why sed wont remove my empty lines?

Can someone PLEASE explain to me why this sed command wont remove the empty lines? sed -e 's/\r//g' -e '/^{$/d' -e '/^}$/d' -e ':begin;$!N;/^state-text: {[[:space:]]\n/s/\n//;tbegin;P;D' -e ...
2
votes
5answers
483 views

How to use the sed command to only show the first column and last column in a text file

I need some help to figure out how to use the sed command to only show the first column and last column in a text file. Here is what I have so far for column 1: cat logfile | sed 's/\|/ /'|awk ...
3
votes
4answers
296 views

How to use Sed to replace all characters before colon?

How do I replace the following string hd_ma_prod_customer_ro:*:123456789:john.doe with john.doe Basically I need to look for the last colon (:) and delete everything before and including it.
1
vote
1answer
27 views

Move data row(s) to single column while retaining row header(s)

I have reports that are generated in the following tab-delimited format: UNIT TC CC PC TCP FTX FRX HOUSE 55 65 75 85 95 105 CAR 100 200 300 400 500 600 H2 ...
1
vote
3answers
136 views

awk for loop for each line in a file

I'm a newbie to bash scripting. I need help trying to figure out how to get loop through a text file and for every line take the fields of name , project #, and email, and replace them in a email ...
1
vote
2answers
54 views

Append a column

I've trawled through here and a few other places to try and find an answer to this, but it seems so stupidly simple that no one has answered it. All I need to do is add a single value in a new column ...
3
votes
2answers
91 views

How can I derive an IPv6 address from a MAC address?

We know that we can use the MAC address to create an interface identifier, e.g. for a link-local IPv6 address which should be unique in the Network. The image shows the way to do this: My ...
1
vote
3answers
51 views

end of line in linux and mac

I am analyzing a text file looking for a path that is written after a line that starts with "output". The line is something like output xyz/mypath/ and I want to extract xyz/mypath without the ...
1
vote
5answers
107 views

Use SED or AWK to move string to new column and row

I have a .csv file that is tab delimited and I need to move the header row information to a "new" column at the beginning and a specified numbers of rows down. Please forgive any formatting errors for ...
1
vote
3answers
52 views

colourize the first part of each line

I have some chat logs like: (15:12:56) rubo77: mist migration (15:05:22) hans: ist hugo da? (15:36:13) rubo77: test (13:30:15) rubo77: what are the access data? (15:06:38) someone@jabber.ccc.de: user ...
1
vote
3answers
139 views

GREP / SED or AWK: Print entire paragraph in a file on pattern match

I have a file with hundreds of paragraphs of around 15 lines each. I need to search for a pattern, say Occurance: 1. If this pattern is found in the para, I need to print the entire paragraph. Note ...
1
vote
2answers
73 views

Compare set of values from two files and print the output in third file in awk

Hi friends i have problem with comparing two files.I'll try my best to explain.I have two file f1 and f2 which i have to compare on basis of two sets Parameter(p) and Value(v). Basically f1 contains ...
1
vote
3answers
117 views

Convert all text from uppercase to lowercase and vice versa?

My question is how can I convert all text from uppercase to lowercase and vice versa? That is to change the cases of all the letters. It has to be done with a sed replacement somehow.
2
votes
2answers
64 views

Sed : Delete between the first n lines the ones with a given string in them

I have given a string and a file. I have to delete between the first 30 lines the ones having the given string. Tried something like sed -i '/pattern/1,30d' filename Yet it gives errors. More ...
4
votes
2answers
160 views

\n prints an n instead of a newline when using sed in MaxOSX

It's a general problem when I use sed but \n works when I use it outside of sed. This is one example of what I get with sed. I have the file myfile with the following content: 1 2 3 4 5 When I use ...
2
votes
1answer
54 views

sed's c command outputs current line no matter what

Here's what I do: $ echo '1 2 3' | sed -n ' x c\ test x ' test test test Is it expected behavior? I'm running gnu sed 4.2.1.
1
vote
3answers
36 views

Shell command to remove the first string that is enclosed with slashes

I need a shell command(sed or awk is preferred) to remove the string that is enclosed within the slashes. For example If my string is /some/dir/example/ then the output should be dir/example/
1
vote
4answers
60 views

Remove only given strings from given column?

INPUT: <tr><td>FOOBAAR</td><td>FOOO</td><td>BAAR</td><td><font style=BACKGROUND-COLOR:red>2014-02-14 ...
4
votes
6answers
129 views

sed first n occurrences result set between 2 tags / patterns

I have a big XML file and I get all occurrences between 2 tags: Here is what I do: sed -n '/<tag>/,/<\/tag>/p' file.xml And I need to filter to get only first N occurrences. I've ...
2
votes
1answer
90 views

How to replace a leading zero with white space in SED?

Trying to find how to replace a leading zero with white space in SED. Attempting to get day of month and replace with space to filter some data that I am screen scraping. The code I have is as ...
2
votes
1answer
54 views

Remove all the new lines in a text file using sed [duplicate]

I would like to remove all the new lines in my text file with sed, I use this code: sed -i-o 's/\n//g' mytext.txt but nothing changes. I must be missing something... That is the content of my ...
0
votes
3answers
61 views

Removing user entry from /etc/passwd

I am trying to create a sed statement to remove ftp and other users which we don't need on our Redhat 5/6 servers. I am trying to create a sed pattern so I can find for example ftp and it removes the ...
0
votes
1answer
36 views

Remove given parts of a string with sed?

$ echo '<a href="mailto:NA?Subject=AB42525216 - FOOBAR bla bla - bla">NA</a>' <a href="mailto:NA?Subject=AB42525216 - FOOBAR bla bla - bla">NA</a> $ echo '<a ...
-1
votes
4answers
60 views

SED not Deleting lines

Can anyone tell me why sed fails to delete the lines containing 0 in the last column. I have used the following and nothing seems to work. sed "/0/d" sed "/ 0 /d" sed "/\t0\n/d" sed "/0\n/d" ...
1
vote
3answers
114 views

Returning only the portion of a line after a matching pattern (Unix)

I have a parent folder (abeps) which contains several sub folders (1,2,3....25) where output file is located, one in which - all are the same name (opt.out). In this files there is an unpredictable ...
0
votes
4answers
45 views

compare columns in a one file and print the count of matches

I have a CSV file that contains two columns. I want to compare the two columns and print the number of matches. file1 M,M A,M A,A M,A Expected output: If the first columns in the first row is the ...
0
votes
1answer
27 views

sed replace misplaces slashes

I have the following code in a LaTeX file: for \emph{service} in \emph{host}.resources: for \emph{file} in \emph{host}.resources: \underline{service}.requires.add(\underline{file}) ...
0
votes
4answers
154 views

Search for a Value only in one column w.o using awk, sed, or perl

I have a file that looks like this : Marketing Ranjit Singh FULLEagles Dean Johnson Marketing Ken Whillans FULLEagles Karen Thompson Sales Peter RobertsonPARTGolden ...
2
votes
3answers
132 views

replace column of a csv file with column from another file

I have two sample files like this: $ cat file1 abc,sachin cat,kumar $ cat file2 xyz pressure $ cat file3 xyz,sachin pressure, kumar I want the first column of file1 to be replaced with file2. ...
0
votes
4answers
62 views

Print text between tags (inclusive) if certain text is found

I've got a task to extract data from several Apache servers. The task is to print out: <Directory ...> ... </Directory> where +ExecCGI is located within. Let me give an example to ...
0
votes
4answers
120 views

extract value between two search patterns on same line

I have the following in a file Output.dat. I need to extract the value between dn: uid= and ,ou= dn: uid=user1,ou=Active,ou=Member,dc=domain,dc=org dn: ...
-3
votes
1answer
149 views

how to select specific range of line & count the specific occurence of the first charcter w.r.t. each unique second charcter? [closed]

Hi I have a file like this : #0 0:() 1b:cg*b 1c 0:cg xe #4 0:() 0b:cg*b xc 0:cg 1e #8 0:() 0b:cg*b xc 0:cg xe #12 1b:cg*b xc 0:cg 0e #16 xb:cg*b 1c xe #20 1:() xb:cg*b xc 1:cg 1e #24 x:() xb:cg*b xc ...
3
votes
2answers
75 views

how to grep complex hierarcy?

I have a file as:- start apple 1 a 2 b 3 c start orange 4 a 5 b start mango 1 a start a/b/c 5 z end 4 b end 6 c end start banana 3 c end 4 d 5 e end I want the output as :- 1 apple/a 2 apple/b 3 ...
1
vote
1answer
38 views

Delete a matching line in a file doesn't work

So, I have this piece of a code: while read line do if [ $line = $maddr ] ; then sed -i '/${maddr}/d' mailinglist found=true ...
1
vote
1answer
65 views

What can I know about this part of code? [duplicate]

What does this part of a script do? This is a part of a scrpt in bash for j in *.* ; do cp $j ../../$name-S$i.gid/data/${j%%.*}$i.${j#*.} sed "s/$name-S/$name-S$i/" $j > ...