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

learn more… | top users | synonyms

5
votes
3answers
188 views

Extracting data from complex file structure

I have a txt file that is a dump from a database, that contains one entry per line. The structure is like this: 1500 29/03/2010 18 02 09 47 17 45 28.248 0 0.01 130 12.721 7908 298,809 YES ...
1
vote
4answers
2k views

Convert all text from uppercase to lowercase and vice versa? [duplicate]

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.
0
votes
1answer
40 views

How to escape unbalanced brackets or slash in sed?

I'm trying to use sed, but my pattern contains [] brackets and slashes (/). I've tried quotes, but it doesn't help. How do I escape it? Examples: $ sed -i'.bak' "s/^includes[] =/;includes[] ...
-1
votes
2answers
97 views

reading from file using the command sed

I have a list of folders (the name of those folders mentioned in the file list.txt).I wanted to read the line 2 in all the files (the files in the folders has the same name) and print that line in a ...
14
votes
10answers
3k views

There must be a better way to replace single newlines only?

I am in the habit of writing one line per sentence because I typically compile things to LaTex, or am writing in some other format where line breaks get ignored. I use a blank line to indicate the ...
1
vote
0answers
26 views

OpenWRT missing OD (octal dump)

I have a bash function using od command. Now I'm trying to run in on OpenWRT and see that in has not od. Also can't find it using install from opkg, because I can't find it. Is there a possibility to ...
0
votes
2answers
98 views

Replace regex capture group content using sed

I'm trying to edit my nginx.conf file programmatically, which contains a line like this: access_log /var/log/nginx/access.log; which I want to look like this: access_log ...
0
votes
3answers
83 views

How do I search a file for a string then use it as a variable?

I have an XML file that looks like this: <id>456</id> <root> <value>1</value> <intNum>2</intNum> </root> <root> <eulav>1</eulav> ...
0
votes
2answers
73 views

Match a whole word (IP address) using `sed`

I have the following line style in a file: 1.2.3.4 1.2.3.4a 1.2.3.45 iaa1.2.3.4ad 11.2.3.4a a1.2.3.4 1.2.3.4> <1.2.3.4> <"1.2.3.4"> 1.2.3.4 hostname I want to replace all the ip ...
0
votes
2answers
44 views

Delete consecutive lines if patterns match in each line

Good day, I was wondering how to delete to consecutive lines when this pattern is found: /^pt [a-z]\npy [0-9][0-9][0-9][0-9]\n// Expected Input pt a py 01234 pt b cd abc py 5678 Expected Output ...
1
vote
0answers
36 views

Why doesn't this sed substitution for a non-ASCII byte work?

I tried this substitution with GNU sed on OS X (4.2.2 installed through Homebrew). But it doesn't work. printf "Hello\x92 World" | gsed -r "s/[\x92]/'/g" The expected output is: Hello' World The ...
4
votes
4answers
345 views

How do I remove every number that's surrounded by <>

I have tried this sed -i '' 's/[0-9]*<>/g' But it didn't work. Example file: <Number1> </Number8> output: <Number> </Number>
4
votes
3answers
90 views

How can I replace a newline with sed?

I've got text with whitespace (including a newline) that I need to replace. I'd like to use sed, but AIX doesn't seem to support the answers to sed newline questions I found. The version of bash I'm ...
1
vote
1answer
46 views

How to nest global matches with sed?

If I do: sed 's/match/replace/g' I know that sed will substitute replace for every occurrence of match on a line. But what if...? echo "match <please dont match this?>" | sed ...
2
votes
1answer
53 views

Return count of matches with find/replace using sed

I'm trying to get a count of the number of replaced strings with find and sed. What I'm starting with: # find . -name \*.php -exec sed -i -e "s|finddddd|replaceeeee|g" {} \; This replaces four ...
5
votes
2answers
68 views

How to wait for execution of parallelized processes and stitch together the outputs?

Quite new to doing things on Unix, looking to make a script that does the following things in order: Take main .tsv file, split into X number of files with Y lines each Run each split file through a ...
0
votes
2answers
57 views

How to list only filenames removing directories and subdirectories

How can I get the list of only filenames and remove directory and subdirectories using find, sed, awk, cut or any. For e.g : I get list of all media files using find as such: find /var/warehouse/* ...
2
votes
4answers
60 views

Awk remove field only if numeric

ls /var/log/packages/*SBo|cut -d / -f 5 return webcore-fonts-3.0-noarch-3_SBo winetricks-20120923-noarch-1_SBo wireshark-1.12.1-x86_64-1_SBo wxGTK-2.8.12-x86_64-3_SBo I want to substitute from ...
1
vote
1answer
48 views

Linux log file structure change for usage with kst

My file (tcp dump from networked sensors) has this shape: 20:06:57.049686 IP (tos 0x0, ttl 64, id 26871, offset 0, flags [DF], proto UDP (17), length 68) e108-193.eduroam.tugraz.ac.at.34225 > ...
5
votes
4answers
288 views

sed ranges aren't always able to match only one line

Consider the following range: 1,/pattern/. If pattern matches on the first line, the range matches for the whole file: $ cat 1.sh #!/usr/bin/env bash set -eu seq 1 4 | sed -rn '1,/'"$1"'/p' $ ./1.sh ...
0
votes
1answer
190 views

Add text to end of every line

I have tried a lot of commands, like this: sed -i '' "s/$/<@string>/" txt.txt > txt2.txt This makes txt2.txt empty, why?!? sed 's/$/<@string>/' txt.txt > txt2.txt This does ...
3
votes
2answers
121 views

How to read needle part of the sed command from a file?

I want to replace a long part of a file with something else preferably by sed but want to read that long part from a file. I already found this: sed -e '/<TEXT1>/{r File1' -e 'd}' File2 from ...
3
votes
2answers
2k views

How can I get my sed command to make permanent changes to a file?

Is this possible? I read somewhere that the following command would do it: sed -e [command] [file] but it appeared to do the same thing as just sed [command] [file] (it did not save the ...
3
votes
4answers
278 views

Decreasing a number with sed

I extracted the metadata of a PDF in a .txt file using pdftk, and now I am trying to decrease the BookmarkPageNumber value for each bookmark by an integer. The .txt has these lines: BookmarkBegin ...
1
vote
2answers
59 views

Extract and format data with `cut` and `awk`

I have the below file in txt: "Firstname","Lastname","Company" "Alex","Johnson","Alex Corp." "Baran","Atasoy","Gülerler Ltd." I would like to extract and format data by using awk and/or cut and ...
10
votes
3answers
11k views

Replace string with contents of a file using sed

I have two different files: File1 /home/user1/ /home/user2/bin /home/user1/a/b/c File2 <TEXT1> <TEXT2> I want to replace the <TEXT1> of File2 with the contents of File1 ...
3
votes
1answer
108 views

What is the purpose of those special characters in the sed command?

I found this bash command that creates a directory tree in your console window. I find it quite useful, but I don't really understand how all of the special characters work. Could someone help break ...
2
votes
3answers
224 views

Using grep/awk/sed to sort and combine 2 files

Ok I am running into a problem. I am taking a wifi log that has MAC addresses listed in it. I want to find out what MAC vendors/manufactors for the devices that are connected to my router. I have 2 ...
2
votes
4answers
58 views

Linux log file structure change, abnormal (?) sed behaviour

Ok, so I tried to get this 0x0000: 4500 0044 68f7 4000 4011 25c7 8083 d0bf E..Dh.@.@.%..... 0x0010: 8083 da24 85b1 15b3 0030 1e8b 3132 3033 ...$.....0..1203 0x0020: 3132 2e37 3836 3036 2c20 ...
3
votes
2answers
178 views

Shell script to assign values from a lookup table is too slow

I'm trying to assign some variables from a lookup file with a shell script. I have something working but it seems unnecessary slow. Script: while read line do ...
1
vote
1answer
41 views

sed : replace 1 word without repeating the rest of the sentence

Say I have the following pattern : foo bar with foo being always the same, but bar can change. I have an hash table that, for each value of bar, has a new one. I am new to sed so the thing I do now ...
5
votes
4answers
365 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 ...
3
votes
2answers
95 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 ...
1
vote
1answer
55 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 ...
3
votes
2answers
42 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. ...
0
votes
1answer
33 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
59 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 ...
1
vote
2answers
83 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 ...
0
votes
0answers
25 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 ...
5
votes
1answer
2k views

Replacing multiple lines in sed or awk [closed]

I'm trying to use sed or awk to replace 5 lines in a smb file but I just don't have any idea how to deal with the newlines.
1
vote
4answers
160 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
3answers
79 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
53 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
3answers
283 views

Replace specified character between two strings?

i have something to accomplish. i need to replace all occurrence of & inside or between <ex> </ex> to #. actual example below: a & b & c <ex> a & b & c ...
0
votes
2answers
262 views

any command that can format html or xml from shell? [closed]

There must be something on the lines of sed? Normally in sed you type something like: echo day | sed s/day/night/ the shell prints "night". Is there something that can take a file (containing ...
-1
votes
1answer
131 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, ...
2
votes
2answers
51 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 ...
0
votes
1answer
100 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
53 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
48 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 ...