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

learn more… | top users | synonyms

-1
votes
0answers
21 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. ...
1
vote
3answers
67 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
68 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
38 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 ...
5
votes
3answers
204 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
269 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
3answers
46 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
923 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
8answers
2k 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
169 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
36 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 ...
3
votes
6answers
3k 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
2k 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
44 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
2k 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
62 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 ...
5
votes
2answers
143 views

How to use shell to 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
65 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
338 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
64 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 ...
2
votes
3answers
686 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
118 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
797 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
99 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
183 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
56 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
44 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
79 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
320 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
155 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 ...
3
votes
1answer
111 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
91 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
48 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
101 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
141 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
65 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
32 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
304 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
647 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
78 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
647 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
167 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
85 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
47 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 > ...
1
vote
2answers
174 views

Regular expression find 3 or 4 numbers

So, I have 50+ words and I have to match the numbers in them. These numbers can be 3 or 4 digit numbers. I think I tried every way there is, but nothing seems to work (I need to remember the number as ...
0
votes
1answer
151 views

Search for pattern across multiple files and replace a sub-part in all occurences

I am helping a friend with her thesis written in LaTeX and I need a quick solution for a "search and replace". Using a terminal in Linux, how can I find the following pattern: \caption{*\cite{*}} ...
1
vote
3answers
3k views

Delete lines from a file using awk or sed based on the variable from previous command

I have a CSV file (say temp.csv) with strings and numbers. I need to delete the lines which contain a particular pattern of string at the beginning of the lines in the file. For example, here is my ...
2
votes
1answer
76 views

How to ensure that string interpolated into `sed` substitution escapes all metachars

I have a script that reads a text stream and generates a file of sed commands that is later run with sed -f. The generated sed commands are like: ...
6
votes
3answers
758 views

Remove only the commas present within the double quotes

In a text file, I want to remove , (commas) and also the " (quotes) (only if the double quotes contains numbers seperated by commas). 56,72,"12,34,54",x,y,"foo,a,b,bar" Expected ouput ...