sed

split text file in two using bash script

I have a text file with a marker somewhere in the middle: one two three blah-blah *MARKER* blah-blah four five six ... I just need to split this file in two files, first containing everything before MARKER, and second one containing everything after MARKER. It seems it can be done in one line with awk or sed, I just can't figure out h...

Shell:How to substitute the field of the text while keeping the same blank space

I want to substitute a certain filed of the text while keeping the same blank space: For example, my text is: Please help me with this problem Any suggestion or help will be appreciated Thanks to all who give help And I want to replace the sentence "Any ...

[Awk/Sed] How do i print word after regex but not a similar word?

I want an awk or sed command to print the word after regexp. I want to find the WORD after a WORD but not the WORD that looks similar. The file looks like this: somethingsomething X-Windows-Icon=xournal somethingsomething Icon=xournal somethingsomething somethingsomething I want "xournal" from the one that say "Icon=xournal"....

Hex to Dec conversion (pipe with sed)

How can i convert my Hex value to Dec value using pipe after sed. Conversion from 'litte endian' to 'big endian' dec_value=`echo dede0a01 | sed 's,\(..\)\(..\)\(..\)\(..\),\4\3\2\1,g'` ...

How to shave off last character using sed?

That is, going from ABCD -> ABC ...

I need to backup and then recover multiple files in different directorys with /bin/sh

As the title say. I need to be able to backup and then recover files. To make the back up was pretty simple if [ "$bup" = "true" ]; then cp $file $file.bak But to make the recovery.. was not as stright forward. elif [ "$rup" = "true" ]; then bak=`find /path/to/file/ | grep .bak` cp $bak ${bak/\.bak} fi It works i...

How Can I Mix Math with Regex's in Awk or Sed?

Hi All, I've used regex's in sed before and used a bit of awk, but am unsure of the exact syntax I need here... I want to do something like: sed -i 's/restartfreq\([\s]\)*\([0-9]\)*/restartfreq\1$((\2/2))/2/g' \ my_file.conf where the second match is divided by 2 and then put back in the inline edit. I've read though that sed ca...

Change file name suffix(es) (using sed ?)

I'd like to change the file name suffix from files (using a bash script), but sometimes there are files with one period and some with two. Now I use this: new_file=`echo ${file} | sed 's/\(.*\.log.*\)'${suf}'/\1.'${num}'/'` Where 'new_file' is the new file name, 'file' the original file name, '${suf}' the file's suffix and ${num} a n...

Can this be done faster (read file, substitute [sed], write new file)

I use this piece of code in my bash script to read a file containing several hex strings, do some substitution and then write it to a new file. It takes about 30 minutes for about 300 Mb.I'm wondering if this can be done faster ? sed 's,[0-9A-Z]\{2\},\\\\x&,g' ${in_file} | while read line; do printf "%b" ${line} >> ${out_file} printf ...

Printing lines from a file where a specific field is matched

Hi, I have many lines of form: A:B:C I want to print those lines(complete) where the 3rd field (fields separated by :) contain a certain pattern. Example: new/old:california/new york:/ms/dist/fx/PROJ/fx/startScript new/old:startScript/new york:/ms/dist/fx/PROJ/fx/stopScript When searching for pattern startScript, the 1st line shoul...

Printing lines from a file where a specific field does not start with something..

Hi, I want to print all the lines where 3rd field (fields separated by : ) DO NOT start with # (to signify that 3rd field is a comment). Please note that there may be space(s) between : and #. Example Input: A:B:#hdfghdfg A:B: #dfdfdfg A:B:C Desired output: A:B:C I tried: awk -F : '$3 ~ /^#/ { print }' run_out5 > run_out6 b...

Help with Replacing Strings on Solaris

I am on a Solaris 8 box that does not support -i option for sed, so I am using the following from a google search on the topic: # find . -name cancel_submit.cgi | while read file; do > sed 's/ned.dindo.com\/confluence\/display\/CESDT\/CETS+DocTools>DOC Team/wwwin-dev.dindo.com\/Eng\/CntlSvcs\/InfoFrwk\/GblEngWWW\/Public\/index.html>EDCS...

How to write find-all function (with regex) in awk or sed

I have bash function which run python (which return all finded regex from stdin) function find-all() { python -c "import re import sys print '\n'.join(re.findall('$1', sys.stdin.read()))" } When I use this regex find-all 'href="([^"]*)"' < index.html it should return first group from the regex (value of href attribute from file in...

SED substitution for variable

I have a file named check.txt which has the below contents: $ cat check.txt ~/bin/tibemsadmin -server $URL-user $USER -password $PASWRD $ I have a main script where the values of $URL, $USER, $PASWRD are obtained from the main script. I want to use the SED utility to replace the $URL, $USER, $PASWRD to the actual values in the check....

insert line into file using rails templates

I am trying to create a rails template that will add code to files at particular line numbers. For example I need to add a route to the config/routes.rb I have tried sed, gsed(only cause I am on a mac and they say that sed has problems with insert and append), anyway, I was not able to achieve the result I want. Any help on this will b...

Need command line expansion to print all keyboard characters

Is there an awk-like or sed-like command line hack I can issue to generate a list of all keyboard characters (such as a-zA-z0-9!-*, etc)? I'm writing a simple Caesar cipher program in my intro programming class where we do the rotation not through ASCII values, but indexing into an alphabet string, something like this: String alphabet ...

how to display all lines from one that match regex in linux.

I want to display all lines from one which match regular expression if I have a file foo bar123 baz12435 lorem ipsum dolor sit amet this display-from baz[0-9]* < file sould return (It doesn't matter if it display matched line or not) lorem ipsum dolor sit amet How can I do this in Linux (with sed, awk or grep) ...

sed extract multiple possible(?) values from a file

Hi Folks I have a file that has multiple lines like the following: "<sender from="+919892000000" msisdn="+919892000000" ipAddress="" destinationServerIp="" pcfIp="" imsi="892000000" sccpAddress="+919895000005" country="IN" network="India::Airtel (Kerala)" "<sender from="+919892000000" msisdn="+919892000000" ipAddress="" destinationServe...

get list of sections from ini-file using bash (sed/awk)

I want to create a var from the section names of an ini file like: [foo] ; ... [bar] ; ... [baz:bar] ;... now I need a var like SECTIONS="foo bar baz" thanks in advance ...

Very basic replace using sed

Really would appreciate help on this. I am using sed to create a CSV file. Essentially multiple html files are all merged to a single html file and sed is then used to remove all the junk pictures etc to get to the raw columnar data. I have all this working but am stuck on the last bit. What I want to do is very basic - I want to repl...