4
votes
4answers
149 views

Bash Scripting : Printing column data in the same row

I have written a bash script to calculate the size of a PostgreSQL database and print the output along with the date when the script was executed in a text file. The script code is as follows: ...
6
votes
6answers
343 views

bash find lines starting with string

I have a bunch of files and I want to find which one contains sequential lines starting with a certain string. For example for the following file : Aaaaaaaaaaaa Baaaaaaaaaaa Cxxxxxxxxx Cyyyyyyyyy ...
4
votes
2answers
227 views

Merge fields in a file

I have a file with 7 columns, a GFF file having chromosomal regions.I want to collapse the rows where REGION ="exon" to only one row in the file.The row has to be collapsed on the basis of regions ...
1
vote
4answers
95 views

How can I delete the first dot before the first number?

How to remove the first dot before the first number? For example I have the following file more file Version …………2.465.76.8.332 I want to get only the version number - 2.465768.332
4
votes
2answers
125 views

How can I delete all unordered lines from a text file?

Overview Consider an ordered list interspersed with unordered elements, e.g.: Alligator Ant Falcon <-- Baboon Badger Armadillo <-- Caiman Cat How can this list be processed so that all ...
6
votes
4answers
374 views

Using sed to add a URL to the start of every line

I have the URL (see below) of a certain web page that lists many different versions of a software package. URL=http://ftp.gnu.org/gnu/wget/ The following one-liner gets me the latest version tar ...
2
votes
2answers
46 views

join sed output

I'm looking to somehow pass the output of the following command: $ sed -n '5p' file-A into $ sed '5 c\ > "string extracted from previous sed command" file-B So basically, I want to replace ...
1
vote
2answers
77 views

bash replace part of string based on location [duplicate]

Sorry I've looked around for a one line solution ( as bash offers ) to replace part of filename. Given that a folder has image sequence like ve2_sq021_sc001_v000.0101.jpg ...
1
vote
2answers
54 views

Different behavior of sed with respect to an array and a string in the presence of backslashes

Let the file foo.txt contain foo\\ bar baz xx Why does the following correctly change "foo\\ bar" to "someotherstuff" in foo.txt? sed -i 's/foo\\\\ bar/someotherstuff/gI' foo.txt while this ...
1
vote
1answer
52 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 ...
5
votes
6answers
392 views

Replace a character except last x occurences

I have a file that has a bunch of hostnames correlated with IPs that looks like this: x-cluster-front-1 192.168.1.2 x-cluster-front-2 192.158.1.10 y-cluster-back-1 10.1.11.99 y-cluster-back-2 ...
1
vote
3answers
270 views

Remove whitespace and parentheses in filenames with sed [duplicate]

I'm an absolute newbie in the unix area so forgive me off the bat if I've gone about this the wrong way. I have a series of files I need to rename which all have the pattern " (*)" in them. Eg; ...
3
votes
1answer
84 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 ...
6
votes
3answers
266 views

emulate tail with sed

I have a mini-system with only limited number of binaries (bash,cp,cat,sed, ...). I don't have tail command, and I am wondering if I could emulate tail functionality with sed cat foo.txt | tail -n 10 ...
-1
votes
1answer
74 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: ...
1
vote
1answer
59 views

Using sed output in another script or command

How can I use the output of sed in another script? For example (this doesn't work): sed -n "$COUNTER",1p /domains.csv | wget or sed -n "$COUNTER",1p /domains.csv > /myScript.sh As far as I ...
0
votes
1answer
33 views

rearranging from colum to row in a csv [duplicate]

I have a CSV file that presently has an output like this 1 2 3 4 5 what I need to do is reconfigure the output as follows 1 2 3 4 5 all the entry data on one line, any help would be greatly ...
1
vote
1answer
130 views

Problem with sed on a array containing strings containing spaces

I have a array looking like this: array=("(1 2 3) (123)" "2 31 (231)" "4 5 1 (451)" "(te)xt (1234)") This array is a example. It does not look like this but its structure is the same (the strings ...
4
votes
3answers
174 views

How to only output lines that are younger than 3 months?

cat a.txt 1387111124 ./asfjlasdf.txt 1348681215 ./akdfyxcv.txt So I need this: cat a.txt | SOMEMAGIC 1387111124 ./asfjlasdf.txt The output should only have the lines that are younger than 3 ...
0
votes
2answers
184 views

bash script, printing multiple lines that matching to a specific patern

I have a log file and I'm making a script to do some actions. An action is to print a specific area of the log. Every block at the log starts with a specific time stamp and inside the block may have ...
1
vote
2answers
89 views

Ensure /etc/export contains rule using bash

What's a working example of modifying /etc/export using bash? Example: I want to ensure the following rule is present and valid: /export/home 2400:123::/32(rw,no_root_squash) And it should: Add ...
2
votes
2answers
115 views

stripping out the last two [end] with sed?

I'm working on a script that improves the fluxbox 'menu', and my script has this line: sed -i 's/\[end]//g' ~/.fluxbox/menu;sed -i '/^\s*$/d' ~/.fluxbox/menu but this has the unfortunate effect of ...
1
vote
2answers
139 views

What does this regex mean?

I was working on the conversion of Unix newline to Windows newline. I tried to unix2dos but it gave me some binary error, so I looked it up and stumbled upon this regex sed 's/$'"/`echo \\\r`/" ...
4
votes
5answers
292 views

Pattern matching across multiple lines

What is a quick and easy way to validate if the pattern "301 domaname.com 200" is present within BASH when spread across multiple lines of output? I was using something like the following: awk ...
2
votes
2answers
1k views

Insert text in specific lines of a file?

How can insert some text in specific lines of a file? What is most simplest method that I can use? (bash, sed, awk?) What I want to do, might be simple, but I don't know where I should start. It's ...
1
vote
4answers
495 views

How exactly do I create a sed script and use it to edit a file? [duplicate]

I know how to edit a file using sed one step at a time, but how would I create an actual sed script and then use it on the file to do the same things that the individual sed commands would do? For ...
1
vote
2answers
77 views

How would I use sed to detect a certain amount of numbers before it inserts a character? ###-###-####

I need to format phone numbers in a text file. They appear as (example) 8014516912 How would I format it so that I can insert a - after the first 3 numbers, and then another - after another 3 ...
0
votes
1answer
262 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 ...
1
vote
3answers
230 views

Reversing the value key pairs of array using sed or pattern replacement or brace expansion?

#!/bin/bash arr=(a b c d) declare -A brr for i in ${!arr[@]} do brr[${arr[$i]}]=$i done echo ${brr[@]} #0 1 2 3 Is there any way to reverse the values and key pairs ...
1
vote
1answer
638 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 ...
2
votes
2answers
108 views

Sanitize Apache access log files?

We have this code in a shell script that pipes output for Apache to log. declare -a values=( $taintRequestVals ) for item in ${!values[@]} do cat $apacheLog | sed ...
0
votes
1answer
207 views

Sed - unknown option to `s'

I execute a sed command in my script: sed -i "${1}s/${2}=.*/${2}=${REPLY}/" $3 this is the echo: sed -i 13s/log4j.appender.ROOT2.File=.*/log4j.appender.ROOT2.File=/app/TET/log.log/ ...
0
votes
1answer
115 views

Assign sed result to a variable

I have a sed command and I would like to assign the result to a variable. My command is: sed -n 's/^Release:\s*\(.*\){?dist}/\1/p' file.spec And I tried var = $(sed -n ...
3
votes
3answers
2k views

importing data from a text file to a bash script

I need to import a text file like this below: AMBI CBNK CCXI CERE CLACW CNYD DAEG DLIA DLLR DNDN DSGX HAST HIBB, HPOL IRDMZ MARK NEPT NFEC NINE NRCIB OMER PLCC PLPM PSUN UNTK There are 25 entries, ...
0
votes
6answers
1k 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 ...
1
vote
1answer
110 views

Searching for all the array elements in another array?

This is how I would search for an element in an array. count=${#ARRAY[@]} lsearch() { status=-1 for((i=0;i<count;i++)) do Temp=$1 if [[ $Temp -eq ${ARRAY[i]} ]] then ...
2
votes
2answers
980 views

Comparing two files using Unix and Awk

I need to compare two files, File1 and File2 (Separated by space) using 4 fields (Field 1, 2, 4 and 5 of File 1 with field1, 2, 4 and 5 of File2). Logic: If column 1, 2 and 4 of File 1 matches with ...
2
votes
6answers
149 views

Bash - Split the previous commands parameters

How would one parse the previous command in bash? Example: root$ ssh foo@1.2.3.4 root$ echo !$ &>/tmp/foo.txt root$ cat /tmp/foo.txt foo@1.2.3.4 Goal: Send just the ipaddress 1.2.3.4 to ...
1
vote
3answers
117 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 ...
9
votes
8answers
795 views

How to remove multiple newlines at EOF?

I have files that end in one or more newlines and should end in only one newline. How can I do that with Bash/Unix/GNU tools? Example bad file: 1\n \n 2\n \n \n 3\n \n \n \n Example corrected ...
0
votes
2answers
320 views

sed - replace complex lines in a file using variables

How do I replace a complex line in a file using sed? For example I want replace a udev rule in /etc/udev/rules.d/70-persistent-net.rules. This doesn't work: OLD_RULE='SUBSYSTEM=="net", ...
2
votes
2answers
358 views

Add a suffix string to end of each line? [duplicate]

I have two files: file01: line1 line2 line3 file02: A B C And I want to get line1 A line2 B line3 C I could possibly write a Perl script but it is better if I don't need to. I have tried ...
4
votes
4answers
381 views

What does <<< mean? [duplicate]

What does <<< mean? Here is an example: $ sed 's/a/b/g' <<< "aaa" bbb Is it something general that works with more Linux commands? It looks like it's feeding the sed program with ...
-1
votes
1answer
146 views

SED command and filenames with space

I was hacked, for my php files was infected. Example: http://www.nwww.ma.mk/oscommerce/configweb/apexfash-wp-blog.txt Bad Code: <?php ...
-2
votes
3answers
180 views

run file from different directory [closed]

I have a directory mainfolder with a subdirectory execution which contains a configure script. I can switch to the execution directory and run ./configure and it works fine. Now I'm trying to figure ...
0
votes
3answers
142 views

Inserting the results of a for loop into an html file - BASH

I have a script that takes the results of a command and puts them into a html code. Here's what I have so far... #!/bin/bash list_dir=`ls -t downloads/` for i in $list_dir do #---- # echo ...
2
votes
3answers
1k views

Easy way to parse syslog date format

I'd like to write a script that analyses the last week's syslog. But my syslog logs in a stupid date format, e.g. "May 22". If it logged as 2013-05-22, this task would be trivial. Is there a way ...
5
votes
4answers
315 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 ...
1
vote
2answers
161 views

Split using sed

I have to split [X] ||| you owns the [X,1] ||| you own the [X,1] ||| 1 0.02020 0.07847 0.36788 3 -0.00000 -0.00000 at the pipes and output those line whose 2nd and 3rd argument are different.
2
votes
2answers
769 views

Using sed to process passwd file

I am trying to learn sed, but I'm having a lot of trouble. What I am trying to do is process my passwd file using a bash script with sed commands to do the following: For every user with group ID ...