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

learn more… | top users | synonyms

1
vote
2answers
593 views

Parsing the output of date with sed

I am trying to replace the whitespaces in the output of date with '_' with no success. $date Fri Sep 14 14:10:04 EDT 2012 $ date | sed 's/ /_/' Fri_Sep 14 14:10:24 EDT 2012 As you can see, the ...
2
votes
1answer
416 views

Using sed, how can I replace a line containing a pattern with contents from another file?

input_file.txt: one fffds two xxxx three ffff four ffde data_file.txt: six seven I want to replace the line containing two xxxx in input_file.txt with the content of data_file.txt. The output ...
3
votes
4answers
4k views

How to get all lines between first and last occurrences of patterns?

How can I trim a file (well input stream) so that I only get the lines ranging from the first occurrence of pattern foo to the last occurrence of pattern bar? For instance consider the following ...
3
votes
3answers
1k views

with sed, how can I replace word within a matching line?

I am trying to write a sed expression to detect lines similer to this: s0:12345:respawn:/sbin/agetty -8 -s 115200 ttyS0 linux and replace the "ttys0" with "something_else" I do not want to detect ...
3
votes
4answers
386 views

Piping paths with different types of quotes for slash substitution

I would like to use sed to convert a path with backslashes to the same path with forward slashes: E.g. I would like to pipe \\path\to\file\ and obtain /path/to/file None of the following commands ...
6
votes
4answers
3k views

Concatenate lines by first column (AWK or SED)

How can I use AWK in the following situation? I want to concatenate lines that start with the same column. Only the first column is kept after the join (in this case aaa, www, hhh). The file may be ...
0
votes
5answers
5k views

compare two files get identical list

file1.txt (50 lines) TERYUFV00000010753 TERYUFV00000009526 file2.txt (500 lines) TERYUFV00000009526 refids_739_known_8/10_target TERYUFV00000018907 refids_12023_known_21/22_target ...
3
votes
2answers
1k views

What is the best way to find a list of several strings within a large text file

The short, general question is: In Unix/Linux, what is the best way to find a list of several (about 150) strings within a large text file? I am asking this to all Unix/Linux experts as a general ...
4
votes
3answers
726 views

sed convert 4 spaces to 2

How does one convert 4 spaces into 2 spaces with sed? Is it possible? I found this but it converts tab to spaces: sed -r ':f; s|^(\t*)\s{4}|\1\t|g; t f' file
2
votes
3answers
117 views

Need to parse a double entry table with two pairs

I have this two-entry table resulting from a program output: Variable1 : Value1 Variable2 : Value2 Variable3 : Value3 Variable4 : Value4 Variable5 : Value5 Variable6 : Value6 ...
2
votes
1answer
1k views

update PATH variable in .bashrc using sed

I've been trying to update my PATH variable permanently by putting it in my .bashrc file. However, I don't want to just append it to the file, but rather replace the current PATH=........ with the ...
1
vote
3answers
2k views

How to rename files using sed?

This is an sed expression that was created by a contributor here. More specifically by @craig-sanders. $FileToMove is set to "2012-09-01 Home insurance quote_zz20.pdf" # use sed to extract folder ...
0
votes
2answers
206 views

Getting data from matching list

list.txt GETID_17049_knownids_1/2_Confidence_0.625_Length_2532 GETID_9248_knownids_6/10_Confidence_0.439_Length_2474 GETID_11084_knownids_3/3_Confidence_0.600_Length_1451 ...
1
vote
4answers
4k views

sed/awk/perl - delete spaces between two strings/words + solaris 10

please advice how to delete the spaces between "=" to the value/string ( after the "=" character) , should be implemented by awk or sed or perl command and command must to fit for solaris OS , ( ...
1
vote
5answers
5k views

(Mac Terminal) sed to parse JSON … what am I doing wrong?

In Mac Terminal, I'm trying to parse the "name" out of this JSON response: {"created_at":"2012-08-27T20:04:27Z","deleted_at":null,"id":21462840,"item_type":"video","name":"CastingBy-v12 ...
8
votes
7answers
387 views

Swapping an unlimited number of columns

I have a file with columns. See below for an example: a b c ... z 1 2 3 ... 26 I'd like to swap all columns where the 1st becomes the last, the second becomes the one before last...etc.. z y x ...
4
votes
2answers
143 views

Column mismatch and substituting

input.txt (tab-delimted) TTTTOTTT00000000008 RTTTT899 5.00E-28 TTTTOTTT00000000046 RTTTWRR 3.00E-31 TTTTOTTT00000000051 2.00E-11 TTTTOTTT00000000051 7.00E-12 TTTTOTTT00000000054 ...
1
vote
1answer
114 views

Match slash in bbe

How can I match a forward slash in bbe? If I have this text file called test.txt: foo / bar I can match it in sed like so: sed -e 's/foo \/ bar/it worked!/' test.txt However when doing the same ...
2
votes
1answer
4k views

Delete specific line number(s) from a text file using sed?

I want to delete one or more specific line numbers from a file. How would I do this using sed?
9
votes
2answers
2k views

Using sed to color the output from a command on solaris

I have a ksh script that must work on both linux and solaris. I'm trying to color the output of specific commands. It works on linux (specifically RHEL6), but not on solaris (SunOS 5.10). Command ...
3
votes
2answers
826 views

merging two column

input_file (columns are tab delimited, only column 4 contains spaces) input A B C D;<>X;<>Y 0 C D E F;<>Z;<>X 1 output A B C D;<>X;<>Y;<>apple=0 C D ...
2
votes
1answer
1k views

Using a here-doc for `sed` and a file

The title says it all, I want to use a here-doc for sed commands and provide the file to be read and the output file. I've looked at Here-Documents from Advanced Bash Scripting guide but it does not ...
0
votes
1answer
357 views

wget images with certain path

im looking to only grab images from a document with a certain path for example domain.com/uploads/287167/file_name.jpg only grab those with the uploads/number/filename im currently doing it this ...
4
votes
1answer
4k views

Delete last character in a word but only if the character is there - in bash

How to remove last character only if it's there? input: OpenOffice.org/m openOffice.org/ozm Pers. Pfg. phil. Prof. resp. Roonstr./m roonstr./ozm desired output: OpenOffice.org openOffice.org ...
2
votes
2answers
359 views

How to Wrap a file with Tags in Bash

I have an xml file named test.xml, without a root tag like this: <cat></cat> <name></name> <id></id> <cat></cat> <name></name> ...
1
vote
4answers
2k views

Appending a string containing escape character with sed

Currently I use: sed -i -e "5a\\ ${text}" $filename to append something to a certain line, where the variable text contains a string such as "\epsilon". When using echo -E $text the string is ...
5
votes
3answers
482 views

Gedit or an other non-commandline editor with the ability to spell-check two languages at the same time

I'm searching for an editor with the ability to spell-check two languages at the same time (German and English). Gedit can't do it out of the box. But I want to use Gedit. It should be possible by ...
2
votes
2answers
316 views

Get row data for non-matching column values

I want to read the file (1600 rows) and get rows only the columns have different values (sno1, sno2, sno3 & sno4-should be not be equal value) and it should be above 50%.The example of output ...
4
votes
4answers
7k views

How to get only filename using sed

How can I get only the filename using sed? I've this out_file=$(echo $in_file|sed "s/\(.*\.\).*/\1mp4/g") But I get the path too /root/video.mp4, and I want only video.mp4.
3
votes
2answers
349 views

Print row contain maximum and minimum value

I need to read the file (contains 16K rows)and print the entire row if any of columns and all columns contains max value (100) and all columns contain min value (0).The ouput example is given ...
4
votes
5answers
1k views

extract fields from “tail -f” of a syslog stream

Example line from syslog file: Aug 1 10:25:50 10.10.10.1 id=firewall sn=XXXX time="2012-08-01 14:35:18 UTC" fw=x.x.x.x pri=6 c=1024 m=537 msg="Connection Closed" f=11 n=195273698 ...
2
votes
3answers
11k views

Sed : Replace pattern on every second occurence?

Is there a way to tell sed to replace the pattern on every second occurrence? Or at least on every second line? (Sure it's possible with a script, but I was asking myself if sed can do it to). ...
2
votes
1answer
388 views

Oneliner to detect camelcase variables

I would like to insert some style tests as git hooks in order to stick with precise style rules. How can I come up with a oneliner that detects and prints arbitrary camelcase variables like the ...
6
votes
3answers
916 views

Print a line only if the next line does NOT contain a particular match

I am trying to search a log file for logged activities that did not complete. For example, I log a "Starting activity for ID 1234..." and if successful, the next line will be "Activity 1234 ...
1
vote
2answers
261 views

Matching values within columns

I have tab-delimited text file containing about more than 1500 rows. input.txt id sno1 EN1 Nucus_2158_mri_1/2_Co_1.0_Le_3104 EN2 Nucus_2158_mri_4/2_Co_1.0_Le_3104 EN3 ...
4
votes
2answers
4k views

Working with columns - awk and sed

I am trying to parse a text file that is generated by an expec script that pulls down some information from a switch. Here is a sample output: 192 0000.0000.0000 1/g23 Dynamic ...
1
vote
2answers
153 views

Can sed be used to generate a load file for my date lookup fact table?

I have an SQL fact table which is used for looking up a date and returning another date. The table schema is as follows: TABLE date_lookup ( pk_date DATE, plus1_months DATE, plus2_months DATE, ...
6
votes
1answer
8k views

Only return the matched string in sed [duplicate]

Possible Duplicate: Extracting a regex matched with 'sed' without printing the surrounding characters How do I make this only print test: echo "atestb" | sed -n 's/\(test\)/\1/p'
7
votes
3answers
2k views

How can I instruct BSD sed to interpret escape sequences like \n and \t?

I have a sed replacement command that I would like to be compatible with BSD sed as well as GNU sed. Extended regular expressions are not an issue as I do not need them in this case. My primary ...
4
votes
2answers
7k views

Compare two file columns

I have long text files with space-delimited fields: cat file1.txt Id leng sal mon 25671 34343 56565 5565 44888 56565 45554 6868 23343 23423 26226 6224 77765 88688 87464 6848 66776 23343 63463 ...
2
votes
2answers
600 views

remove only specific text occurrences from string using sed

I have a text file that contains many rows of this sort of thing: /*[17:51:27][1 ms]*/ UPDATE `country` SET `region_id` = '4' WHERE `country_id` = '36'; Is there a way that I can use sed to remove ...
3
votes
2answers
445 views

Parsing a text-file table and aggregating information

I have long text file with the following columns, space-delimited: Id Pos Ref Var Cn SF:R1 SR He Ho NC cm|371443199 22 G A R Pass:8 0 1 0 0 ...
2
votes
1answer
475 views

Duplicate selected words with sed and replace it

I have to modify a document containing xml data; one modification I couldn't set up with sed. I have to modify the following expressions from: <Bild ...
4
votes
2answers
2k views

delete first line of file only if blank using sed

I have a solution for this in awk: awk '{if (NR==1 && NF==0) next};1' somefile but was unable to find one that worked in sed. E.g., sed -i.bak '/^$/{1,1d;}' somefile ended up deleting ...
10
votes
3answers
4k views

How to sort the string which combined with string + numeric using bash script?

This is the data what I want to sort. But sort treats the numeric to string, the data it no sorted as I expected. /home/files/profile1 /home/files/profile10 /home/files/profile11 ...
3
votes
6answers
2k views

Text file look-up by column

I have a file in this format: [#] OWNER_NAME NAME SIZE [6] Robottinosino Software 200 [42] Robottinosino Ideas worth zero 188 [12] ...
3
votes
2answers
468 views

Change string occurrences in file while respecting DOS new line sequences

I use Visual Studio for my C# development while using Cygwin for some of the tasks that require scripting. Recently I wanted to change all occurrences of string AAA to BBB in my project's files. I ...
5
votes
5answers
976 views

resolve all ip addresses in command output using standard command line tools

I have several log files that contain a bunch of ip addresses. I would love to be able to pipe the data through a program that would match and resolve ip addresses. I.E. cat /var/log/somelogfile | ...
2
votes
4answers
876 views

shorten long lines in a log file

I keep a logfile of a program's output. The trouble is sometimes errors occur dumping very long lines of 7bit ascii data(encoded binary) I don't care to keep. These lines can be 200KB+ long before ...
1
vote
2answers
266 views

How to split vCards lines

Related to How to join vCards lines, vCard does a weird kind of line splitting: If a line contains more than 75 characters, insert a "CR, LF, space" sequence. Thus the following line: ...