Tagged Questions

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

learn more… | top users | synonyms

1
vote
5answers
95 views

Remove backslashes from a text file

I have Input: NISHA =\455 Output: NISHA = 455 I want to remove \ from output. I tried to use command sed "s/[\]//g" P but it is not working and it flags an error: character found ...
2
votes
2answers
164 views

Why does sed outputs “char 53: unterminated `s' command”

Why this bash script ssh $SERVER bash <<EOF sed -i "s/database_name: [^ ]*/database_name: kartable_$ME" $PARAM_FILE exit EOF output -> sed: -e expression #1, char 53: unterminated `s' ...
-1
votes
0answers
18 views

Grabbing table name from views definition using sed

I am little new to linux so please excuse me for my ignorance. I have a text file which basically lists out the view definitions in the database. What I need to know is that what are the tables ...
3
votes
3answers
22 views

Parsing Log Files with sed -e. Need to count unique class names

I have a file, let's call it filename.log, in it I have something like this (2014-11-18 14:09:21,766), , xxxxxx.local, EventSystem, DEBUG FtpsFile delay secs is 5 [pool-3-thread-7] (2014-11-18 ...
1
vote
3answers
49 views

Generate networking configuration files using sed and bash

I am a bit rusty on my scripting abilities and am trying to find a good starting point for creating a script that creates files (generating new file names) and edits the IP address in the file by ...
0
votes
2answers
36 views

how to insert backslash at the front of # symbol?

In bash programming, given a variable, say varA, that store a string containing # symbol. Let's assume varA contain this value: ASD# 1, I need to append a backslash \ at the front of #, so the output ...
1
vote
4answers
114 views

SED command not replacing (working regex)

I'm trying to replace in one of my projects all mysql to mysqli, with their parameters. To do so, I'm searching for all files with mysql in my folder recursively and replacing it with mysqli. Ex: ...
3
votes
5answers
159 views

removing extensions in a column

I have a file like this ILMN_1343291 TGTGTTGAGAGCTTCTCAGACTATCCACCTTTGGGTCGCTTTGCTGTTCG NM_001402.5 ILMN_1343295 CTTCAACAGCGACACCCACTCCTCCACCTTTGACGCTGGGGCTGGCATTG NM_002046.3 ILMN_1651209 ...
2
votes
2answers
107 views

Left and right square brackets treated differently by sed/bash

I have a file with the following contents: [root@server list]# cat filenames.txt [AAA','ACMEDEMO2','ACMEDEMO3','ACMEDEMO4','RENTCOGH','TESTENT','DORASINE','LOKAWINK','BBB] [root@qa4app01 list]# I ...
4
votes
3answers
144 views

Change case of n-th letter in a string

I want to change the case of the n-th letter of a string in BASH (or any other *nix tools, e.g. sed, awk, tr, etc). I know that you can change the case a whole string using: ${str,,} # to lowercase ...
1
vote
1answer
19 views

sed: subsitute in line that contains X but does not contain Y

I am looking for an elegant solution that combines both of these commands: sed -i '/Y/! s/replace/with/' /path/to/file sed -i '/X/ s/replace/with/' /path/to/file I tried sed -i '/X/ /Y/! ...
3
votes
4answers
59 views

Replace a marker in a text file with arbitrary new text

I have a file which contains some text and - on a single line - a marker which indicates where new content should be added foo bar %SUBSTITUTE% foo The line line substitute should be replaced by a ...
3
votes
2answers
194 views

Delete every Nth line in shell

I'm trying to delete a line after N lines using awk and I can't seem to get it right. The file format is like this YYYYYY XXXXXX XXXXXX YYYYYY XXXXXX XXXXXX The real example would be office3 3 1 ...
8
votes
6answers
394 views

How to append Line to previous Line?

I have a Log file which need to be parsed and analysed. File contains something similar like below: File: 20141101 server contain dump 20141101 server contain nothing {uekdmsam ikdas jwdjamc ...
2
votes
4answers
135 views

remove leading string in bash

I try getting this sed command to work. I have a string like rev00000010 and I only want the last number, 10 in that case. I have tried this: TEST='rev00000010' echo "$TEST" | sed ...
6
votes
4answers
288 views

Output part of each line to a separate file

I have a file like this: a AGTACTTCCAGGAACGGTGCACTCTCC b ATGGATTTTTGGAGCAGGGAGATGGAATAGGAGCATGCTCCAT c ATATTAAATGGATTTTTGGAGCAGGGAGATGGAATAGGAGCATGCTCCATCCACTCCACAC d ...
1
vote
1answer
30 views

How to replace a symbol in sed only if it occurs before a letter?

In my documents, I have lots of occurences like these: [["A [["b [["8 [["c [["F [["1... What I need to do is to replace double brackets with single brackets, but only if there is a letter after a ...
3
votes
3answers
153 views

Extracting part of lines with specific pattern using awk,sed

I have a question regarding the awk/sed operators. I have a big file which has following set of lines repeated Expression loweWallrhoPhi : sum=-6.97168e-09 Expression leftWallrhoPhi : ...
1
vote
2answers
87 views

Search 2nd line of files and print filenames to stdout

I have a few directories of ~10,000 files. What's the quickest way to search each file and return the filename if the second line contains a specific string? Edited for clarity
1
vote
2answers
39 views

How can I use sed to remove the first paragraph of the file?

So the paragraph is defined by having a empty line at the end. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc et nisi tristique, facilisis orci nec, pellentesque tortor. ...
3
votes
3answers
191 views

How can I delete all text between curly brackets in a multiline text file?

Example: This is { the multiline text file } that wants { to be changed } anyway. Should become: This is that wants anyway. I have found some similar threads in the forum, but they don't seem ...
4
votes
3answers
139 views

Use sed to delete all but a certain pattern

How do I get just the link part in the http-source of a link? I have <a href="http://unix.stackexchange.com/users/20661/">Unix &amp; Linux and would like to get just ...
3
votes
6answers
115 views

how can I use sed to replace the lists that begins with (*) in a file

Using sed how can I replace the lines that start with a star and replace it with numbers starting from 1? I need to replace the (*) in the fist of a list with numbers using sed for example > this ...
1
vote
4answers
60 views

How to use regex in sed?

I need to revoke the sudo access to the user using sed in scripts. I want to comment the user only if the line contains /bin/su - root Let us consider the file as below, in which I have to comment ...
2
votes
2answers
56 views

Parse several thousand lines of txt into lines and columns

The file at hand lists names, credentials, roles, and privileges for thousands of users. It was passed onto me as .xls but the lines and columns are not arranged in proper form. I have reformated ...
0
votes
0answers
20 views

Replacing code between two JavaScript comments

I need to set a value of JavaScript variable from bash. Variable lives in index.html file and I'd like to use unix SED command to do that. Inside index.html I have it lake this: <script> ...
1
vote
5answers
64 views

Regular Expression for Mixed cased words

I want a regular expression that will help me identify if a certain pattern is present as a mixed case in a sentence or not. Say: Fox juMPed the rock Now, I want to find that if the pattern ...
0
votes
1answer
22 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
65 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 ...
1
vote
0answers
17 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
34 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
75 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
69 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
32 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
28 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 ...
1
vote
1answer
31 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
38 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 ...
4
votes
3answers
80 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 ...
5
votes
2answers
66 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
52 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
53 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 ...
4
votes
4answers
343 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
2answers
352 views

How do I populate end tags using sed, awk or any other command?

I have a txt file that looks like this: <sss>ss< or <firstword>anotherword< I want it to look like this <sss>ss</sss> or ...
3
votes
2answers
107 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 ...
1
vote
2answers
56 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 ...
3
votes
4answers
263 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 ...
2
votes
3answers
154 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 ...
3
votes
2answers
146 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
32 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 ...
3
votes
1answer
104 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 ...