sed

Send the result of multiple commands to one text file?

This is what I have so far - my dropbox public URL creation script for a directory of public URLs (getdropbox.com - gpl I think). My LIST file was created using ls in the following fashion: ls -d ~/Dropbox/Public/PUBLICFILES/* > LIST dropboxpuburl.sh: for PATH in `cat LIST` do echo $PATH dropbox puburl $PATH > ~/URLLIST/$PATH d...

Remove odd lines in a text file

File: /home/USER/DIR/a http://www.here.is.a.hyper.link.net/ /home/USER/DIR/b http://www.here.is.another.hyper.link.net/ Need to remove all the odd lines in this file (PUBLIC-DIRECTORY-LIST)? Its for my batch script which can be found below (dropbox batch puburl creator): for PATH in `cat LIST` do echo $PATH dropbox puburl $PATH done ...

Replace two or more spaces within a text file with a ;

File1: hello world foo bar a word with a space I need to replace all white spaces which are two or more in length with a semi-colon(;). Result: File2: hello;world foo;bar a;word with a space ...

Display and pipe only a specific line of text from a stream

Here is a command line script for a dictionary lookup using Wordnet: #!/bin/bash # Command line look up using Wordnet - command line dictionary echo "Type in your word:" read word /usr/bin/curl -s -A 'Mozilla/4.0' 'http://wordnetweb.princeton.edu/perl/webwn?s='$word'&sub=Search+WordNet&o2=&o0=1&o7=&o5=&o1=1&am...

Remove a variety of lines in a text file

I've been trying to implement a bash script that reads from wordnet's online database and have been wondering if there is a way to remove a variety text files with one command. Example FileDump: **** Noun **** (n)hello, hullo, hi, howdy, how-do-you-do (an expression of greeting) "every morning they exchanged polite hellos" **** Verb **...

Reformat a large text file into one line strings (via BASH)

File1: hello - dictionary definitions: hi hello hallo greetings salutations no more hello for you - world - dictionary definitions: universe everything the globe the biggest tree planet cess pool of organic life - I need to format this (for a huge list of words) into a term to definition format (one line per term). How can one achieve...

How to replace new lines with tab characters

hi i have pattern like below hi hello hallo greetings salutations no more hello for you i am trying to replace all new lines with tab spaces using the following command sed -e "s_/\n_/\t_g" but its not working . could nybody pls help? i need the solution in sed /awk. ...

Merge two text files specific position

I need to merge two files with a Bash script. File_1.txt TEXT01 TEXT02 TEXT03 TEXT04 TEXT05 TEXT06 TEXT07 TEXT08 TEXT09 TEXT10 TEXT11 TEXT12 File_2.txt 1993.0 1994.0 1995.0 Result.txt TEXT01 TEXT02 1993.0 TEXT03 TEXT04 TEXT05 TEXT06 1994.0 TEXT07 TEXT08 TEXT09 TEXT10 1995.0 TEXT11 TEXT12 File_2.txt need to be merged at this spe...

Inline SED regular expression question

I work for a company that offers webhosting and DNS services. We are trying to migrate everything over to new servers and we've often run into stale zonefiles on our servers as customers have changed their authoritative servers to someone else. I am trying to write a script that will check whois, ns, and SOA information to determine if...

How to use sed to test and then edit one line of input?

I want to test whether a phone number is valid, and then translate it to a different format using a script. This far I can test the number like this: sed -n -e '/(0..)-...\s..../p' -e '/(0..)-...-..../p' However, I don't just want to test the number and output it, I would like to remove the brackets, dashes and spaces and output that....

Extracting particular column name values using sed/ awk/ perl

I have an input file say, such as: a=1 b=2 c=3 d=4 a=2 b=3 a=0 c=7 a=3 b=9 c=0 d=5 a=4 d=1 c=9 Assume that the order of column names (a,b, c and d) remains the same. How do I write a script/ command which will help me extract values specific to columns b and d? So my output should be: b=2 d=4 b=3 b=9 d=5 d=1 I could write a "not-s...

What is the difference between sed and awk ?

What is the difference between awk and sed ? What kind of application are best use cases for sed and awk tools ? ...

How to split file on first empty line in a portable way in shell (e.g. using sed)?

I want to split a file containg HTTP response into two files: one containing only HTTP headers, and one containg the body of a message. For this I need to split a file into two on first empty line (or for UNIX tools on first line containing only CR = '\r' character) using a shell script. How to do this in a portable way (for example us...

Capturing the error stream from a sed command

Hello, How do I capture any error from a sed command into a file? Here is the sed command I am using: sed -e 's/'old_word'/'new_word'/' temp_file > output_file Now, when everything goes well, modified contents from temp_file are captured in output_file. But let's say that output_file happens to be read only. In this case, instead...

Remove first three occurrences of space

I need to remove the first three occurrences of space per line in a text file. I have tried the following: sed 's/ //3' This only removes the third occurrence. sed 's/ //3g' This leaves the first three occurrences of space alone and removes all of the following, this is the exactly the opposite of what i want. ...

Bash loop - tokenize on lines rather than words

I'm writing a script to do variable substitution into a Java properties file, of the format name=value. I have a source file, source.env like this: TEST_ENV_1=test environment variable one TEST_ENV_2=http://test.environment.com/one #this is a comment with an equal sign=blah TEST_ENV_3=/var/log/test/env/2.log My script will replace eve...

How can I delete a newline if it is the last character in a file?

I have some files that I'd like to delete the last newline if it is the last character in a file. 'od -c' shows me that the command I run does write the file with a trailing new line: 0013600 n t > \n I've tried a few tricks with sed but the best I could think of isn't doing the trick: sed -e '$s/\(.*\)\n$/\1/' abc Any ideas...

Basic SED question for Linux

Temp file has only the number 22.5 in it. I use sed 's/.//' Temp and I expect 225 but get 2.5 Why? ...

Regex for escaping quotes in a string

I have a string in the file "abc def ghi " klm "ghi "; I want to escape all occurrences of " in the string , output of the result "abc def ghi \" klm \"ghi"; ...

Bash Menu: Return to menu after selection made and executed?

Hi folks. I've got a bash script that writes to a file. at the end of the script I want to display a menu, with line numbers - and have the user be able to select 1 or 2, (etc. up to the number of lines in the file) then have it execute that line. Up to here is perfect. However, after the line is executed (say for example it displays...