2
votes
2answers
31 views

Change path in sql script with sed

I'm trying to change the path in a oracle sql script from a bash script. read -e -p "Enter the ORACLE SID: " -i "orcl" ORACLE_SID_VALUE sed -i "DEFINE tsdir = '/u02/app/oracle/oradata/orcl';/c\DEFINE ...
4
votes
4answers
139 views

extract lines according to a particular column

I have a CSV file like CK,ck XYZ,xyz,xyzs ABC,abc,abcs PQR,pqr,pqrs LMN,lmn, IJK,ijk, I have to check if something is written in column 3 except whitespace, then display the whole line.the output ...
1
vote
2answers
39 views

Using sed with herestring (<<<) and read -a

I use sed with <<< and read to assign all words in a string to variables. What I do is: read -a A0 <<< $(sed '2q;d' /proc/stat) Hence, sed reads the second line of the file file ...
2
votes
2answers
41 views

Sed find and replace with slashes

I am having trouble using sed find/replace with slashes in the find parameter. Sample contents of test.sh str=$(sed -n '/^user:/p' /tmp/shadowtest) # find "user:" line in /etc/shadowtest ...
0
votes
1answer
44 views

Is there a way to create a new file and insert text into this file all with bash? [closed]

I need to change and create several configuration files for some kiosks at work, is there a way to do this with a single bash script? I've heard about SED but the documentation is confusing, could ...
1
vote
1answer
48 views

Handling sed variables with paths in them?

I have an applescript for doing certain things, like search and replace. set lol to quoted form of POSIX path of (choose file with prompt "VälJ Fil") That chooses a file then im doing this set ...
2
votes
2answers
103 views

Replace value within single quotes in a line that contains certain word using sed command

I have a line as below in a html file, shahar.push(['remoteUrl', 'staging.zazzercode.com']); Depending upon environment, I want to replace the remoteUrl value with sed command. eg, ...
3
votes
1answer
49 views

grep upto matching brackets

I have a file like this:- pin(ABC) { a b c d e f { abc } } pin(XYZ) { g h i j k { j k { ...
1
vote
2answers
44 views

rename a batch of files after reading from a source file

I have a directory full of over a thousand files and the names are bit long (and no pattern found in the naming style). I would like to simplify the filenames. E.g.: ...
4
votes
3answers
131 views

Frequency of words in non-English language text: how can I merge singular and plural forms etc.?

I'm sorting French language words in some text files according to frequency with a focus on insight rather than statistical significance. The challenge is about preserving accented characters and ...
2
votes
3answers
180 views

sed + remove the first directory from path

Please advise on how to remove the first directory from a path by sed, (the inverse pf what basename does). For example echo "/mnt/VPfig/Amer/AR4/Celtel/files/COM.txt" | sed ... I should get: ...
3
votes
6answers
74 views

Collapse some repeated parts of successive lines

I have data in notepad like this: 4480-1 4480-2 4480-3 4480-15 4581-1 4581-2 4581-3 4581-4 Can we do it using for loop sort of things? With sed? My required output is ...
1
vote
1answer
35 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 ...
1
vote
3answers
783 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 ...
2
votes
3answers
397 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. ...
-3
votes
1answer
159 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 ...
1
vote
1answer
45 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 ...
2
votes
2answers
109 views

Sed? Stripping all formatting, i.e line breaks and whitespaces, from a report text file, while masking out certain pieces

I am working on a project in which I need to remove all formatting from a text file including whitespaces and line breaks, then replace any colons with pipes. I've made some headway but I cannot find ...
1
vote
4answers
89 views

How to delete a line if string is the only thing on the line

How can I use sed or something else to delete a line only if the string I'm searching for is the only thing on the line? Example output: device-address-binding: ? database-revision: 20 -- ...
4
votes
7answers
325 views

How can I groups numbers in a file

I have a file with numbers in float format. I can review them via sort -rn numbers.txt | less I would like though to be able to "group" them. I.e. easily see how many are in the same range. To give an ...
1
vote
5answers
275 views

Replacing backslashes with commas in Bash

I tried writing a script in which I am reading through a file line-by-line. I am supposed to replace a backslash (\) with a comma (,). The input file is as follows: 1,2,3,WORKSTATION1\A,5 ...
6
votes
4answers
2k views

How to extract logs between two time stamps

I want to extract all logs between two timestamps. Some lines may not have the timestamp, but I want those lines also. In short, I want every line that falls under two time stamps. My log structure ...
1
vote
3answers
2k views

How to delete a line with variable search using sed command

I am new to sed. What is wrong with the sed command on deleting the line which matches the input data? InputData.txt 123, 1234, 1453, Datatodelete.txt 1234,hellofirstline 123,hellosecondline ...
1
vote
1answer
86 views

Shell script to list locked packages in FreeBSD

I'm trying to make a oneliner to be able to list all locked (forbidden to upgrade) packages in FreeBSD. Normally, you issue this command: pkg info -ak It outputs list of all packages in system ...
3
votes
1answer
110 views

Can someone clarify this Bash script

I'm learning something about Bash scripting, and I came across this example: The task is to write a Bash script that reads a file, given with the first argument, pulls out those records that have the ...
1
vote
2answers
75 views

Mailing out a customised content based on specific search in a logfile

Using below test.sh, I am getting result in dump.txt as below: test.sh: #!/bin/bash #"Maxl-script" zone starts..... essmsh -l admin password -s localhost -i << EOF spool on to 'dump.txt'; ...
-1
votes
1answer
119 views

How to use variables in sed

I want to print out the lines of a file between two indices in a Bash script. I have the file name and indices as variables I tried doing this sed -n "$2,$3p" $1 sed: -e expression #1, char 4: ...
9
votes
4answers
135 views

Script to extract selected entries from a bibtex file

I have a large bibtex file with many entries where each entry has the general structure @ARTICLE{AuthorYear, item = {...}, item = {...}, item = {...}, etc } (in some cases ARTICLE might be a ...
5
votes
1answer
257 views

Variable in sed

I have a file that contains filenames with absolute path. In the middle of that path, is a variable directory, whenever I hard code the variable part, it works fine, but when I replace it with the ...
4
votes
3answers
807 views

using sed to replace pattern with hash values

I want to search the file and replace specific pattern with its hash (SHA1) values. For example, let file.txt has the following content: one S56G one two three four five V67X six and I want to ...
0
votes
0answers
26 views

Variable Substitution in sed [duplicate]

I have this script and I need to count the lines inside a file, then pass the number of lines counted to a for loop so that I can get the contents of each line and put it in a variable. My question ...
6
votes
5answers
7k views

Delete First line of a file

How can I delete the first line of a file and keep the changes? I tried this but it erases the whole content of the file. $sed 1d file.txt > file.txt
1
vote
1answer
2k views

How to assign result of sed to variable

Below is a complete copy of a demo I'm using to to figure out to get the sed command to get rid of the spaces in a persons name, and compress it down to not have spaces. Once this is done, I want to ...
1
vote
2answers
446 views

Improve sed command to replace first instance of character and all following characters?

Input: <e1 name="file1" id="id1" anotherId="id2"> Desired output: file1 I can get what I need with this: echo '<e1 name="file1" id="id1" anotherId="id2">' | sed ...
3
votes
1answer
155 views

How can I write a sed script to delete numbers from a line?

Sample File a.b.gg3d 0000000001 0000000001 y a.b.112a 0000000000 0000000001 y a.b.gg3s 0000000001 0000000001 y a.b.1111 0000000000 0000000001 m I have a file that includes about three thousand ...
0
votes
2answers
294 views

sed with auto escape character [duplicate]

CommentAppend() { # Comment line and append line below commented line local comment="$1" # search this line and comment it local append="$2" # Append this line below commented ...
1
vote
6answers
4k views

Using cut/awk/sed with two different delimiters

I have the following cases: case@test.com case_1_2@test.com case_1@test.com I'm trying to convert these to case@test.com case@test.com case@test.com So it should remove everything from ...
2
votes
3answers
1k views

Using a reference to a bash string variable in sed

I'm a relative Linux novice. Suppose that I have a text file a.txt that contains the following text: A B C Now, if I want to change the text on line 2 (which contains B), I can use the following ...
2
votes
2answers
3k views

Passing a variable to sed

I cannot not use a shell variable in sed in the $NUMBER form. I have this line in my shell script: cat shared.txt sed 's/whatever1/$2 ... whatever2/' > shared2.txt The result in shared2.txt ...
1
vote
3answers
134 views

grep for strings that were found in a previous statement

I'm trying to find out if an address definition is used inside of fortigate configuration file. I extracted the section out of the configuration file, that contains the addresses. In that section the ...
5
votes
4answers
454 views

sed how to substitute when string has “http://” in it?

I have a file xx that has the following contents: @base_url = "http://dmstaffing-stage.herokuapp.com/" I want to use sed to eliminate this line (replace with nothing). I have used this sed ...
3
votes
3answers
168 views

checking data in columns when a data or some may be missing or present?

I am not sure if this possible. say i have columns like : Team Colour Game Rainfall PlayerName XYZ Blue Cricket Yes Kapil suppose i need to search ...
5
votes
4answers
2k views

Why is sed giving me an error about an unterminated `s'?

I have a set of sed replacements in a bash script and am getting an error about an unterminated `s' command. Here's what the sed line looks like: sed -n -e "s/TMPFOO1/$FOO1/" -e "s/TMPFOO2/$FOO2/" ...
2
votes
2answers
277 views

add “#” in begining to selected lines in File

Requirement : ADD someting (i.e #) in begining of every line in file A which is grep from file B File A abcd abdc sdfg asdfa jon ram File B jon abcd grep file B from file A and add "#" ...
3
votes
4answers
936 views

Replacing pattern after nth match is found on each line?

I have a file containing lines: india;austria;japan;chile china;US;nigeria;mexico;russia I want to replace all the occurences of semicolon on each line with e.g. ;NEW;, but starting from the 2nd ...
1
vote
1answer
103 views

How to parse this output and put it into an array?

i have expect script whose output looks like : I would like to extract all words like Gi/02/12 etc in an array or a list. VLAN Name Status Ports ---- ...
-1
votes
2answers
3k views

Bash -Extract characters from string

Suppose I have the following variable $string = 'cat somecommandhere' Now the output of the above cat command is test="Thanks serverfault" I want to extract the value between the quotes and ...
2
votes
1answer
91 views

how do i suppress seds unnessary output while using option -e?

why n option is not working here [root@testgfs2 final]# echo a b c | sed -ne 's/[[:blank:]]/"/gp' -ne 's/^/"/pg' -ne 's/$/"/pg' a"b"c "a"b"c "a"b"c" i just need : "a"b"c" actually ...
2
votes
2answers
251 views

changing pattern by removing spaces?

file : hi hello,new york, , ,brazil site ,brazil january,month is feb , , ,indiana jones task: delete all horizontal space (spaces and tab) between any two comas (like , ,) if ...
1
vote
2answers
387 views

reading from a file and changing its pattern into an array?

I have a CSV file containging entries like this : ipaddress,VLAN,VLANid 10.192.168.1,vlan-xyz,3 10.192.168.1,vlan-abc,8 10.192.168.1,vlan-mnp,11 10.192.163.24,vlan-llz,3 10.192.163.24,vlan-bbz,5 ...