sed

add string after each line bash

How do I add a string after each line in a file using bash? Can it be done using the sed command, if so how? ...

awk / sed script to remove text

Hi, I am currently in need of a way to programmatically remove some text from Makefiles that I am dealing with. Now the problem is that (for whatever reason) the makefiles are being generated with link commands of -l<full_path_to_library>/<library_name> when they should be generated with -l<library_name>. So what I need is a script to f...

How to search a file for a pattern and get a new file from the match point to end of file?

I need to take a file and find the first occurrence of a literal string pattern as a complete line of the file: Acknowledgments: And then I wish to create a new file from the line of match all the way to the end of the file. I expect perl is a good way to do this, but I'm not much of a perl person, alternatively maybe sed is a good w...

How to extract comment out of header file using python, perl, or sed?

I have a header file like this: /* * APP 180-2 ALG-254/258/772 implementation * Last update: 03/01/2006 * Issue date: 08/22/2004 * * Copyright (C) 2006 Somebody's Name here * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following con...

Changing the contents of a file with sed in Solaris 10

Hello, I have a bash script that I want to change all occurrences of jdk1.5.0_14 with jdk1.6.0_20 in a file I have the following piece of code : #!/bin/bash myvar="jdk1.6.0_20" sed "s/jdk1.*/$myvar/g" answer_file.1 > answer_file.2 However I have the following information in answer_file.1 (pasting the relevant part): JDKSelection.d...

Assign complex command result to variable

Hi, I have a fairly simple bash shell scripting problem. I want to sed a piece of text and then assign the result of the sed to a variable. #!/bin/bash MOD_DATE=echo $(date) | sed 's/\ /_/g' echo $MOD_DATE // should show date with spaces replaced with underscores. I have tried the above and it doesn't work. Can anyone point out what...

Filtering out emoticons using sed

Hello, I have a grep expression using cygwin grep on Win. grep -a "\\,,/\|\\m/\|\\m/\\>\.</\\m/\|:u" all_fbs.txt > rockon_fbs.txt Once I identify the emoticon class, however, I want to strip them out of the data. However, the same regexp above within a sed results in a syntax error (yes, I realize I could use /d instead of //g, but t...

How do I seperate Punctuations in a sentence with a space between each phrase and punctuation in C++?

I want to write a program in c++ that get a sentence and insert a space between each word and punctuation in it! in sed script this is done with this expression: sed -e "s/,\([^0-9]\)/ , \1/g" -e "s/\.\([^0-9]\)/ . \1/g" -e 's/\.[ ]*$/ ./g' -e "s/\'/ \' /g" -e 's/?/ ?/g' -e 's/\`\`/ `` /g' -e "s/\' \'/''/g" -e 's/(/ ( /g' -e 's/)/ ) /g...

UNIX: Replace Newline w/ Colon, Preserving Newline Before EOF

I have a text file ("INPUT.txt") of the format: A<LF> B<LF> C<LF> D<LF> X<LF> Y<LF> Z<LF> <EOF> which I need to reformat to: A:B:C:D:X:Y:Z<LF> <EOF> I know you can do this with 'sed'. There's a billion google hits for doing this with 'sed'. But I'm trying to emphasis readability, simplicity, and using the correct tool for the corre...

How do make dependency generation work for C? (Also..decode this sed/make statement!)

Hi all. I have a make build system that I am trying to decipher that someone else wrote. I am getting an error when I run it on a redhat system, but not when I run it on my solaris system. The versions of gmake are the same major revision (one off on minor revision). This is for building a C project, and the make system has a global Mak...

Selectively search and replace certain lines using a regular expression

I have a file containing a lot of SQL statements, such as: CREATE TABLE "USER" ( "ID" INTEGER PRIMARY KEY, "NAME" CHARACTER VARYING(50) NOT NULL, "AGE" INTEGER NOT NULL ); COPY "USER" (id, name, age) FROM stdin; 1 Skywalker 19 2 Kenobi 57 I want the column names in the COPY statements to be uppercased and quote...

Regular Expression - Capture and Replace Select Sequences

Take the following file... ABCD,1234,http://example.com/mpe.exthttp://example/xyz.ext EFGH,5678,http://example.com/wer.exthttp://example/ljn.ext Note that "ext" is a constant file extension throughout the file. I am looking for an expression to turn that file into something like this... ABCD,1234,http://example.com/mpe.ext ABCD,1234...

Escape characters contained by bash variable in regex pattern

In my bash script, i am trying to execute following Linux command: sed -i "/$data_line/ d" $data_dir $data_line is entered by user and it may conatain special characters that could brake regex. How can i escape all of the possible special characters in $data_line before i execute sed command? ...

Replacing the last word of a path using sed.

I have the following: param="/var/tmp/test" I need to replace the word test with another word such as new_test need a smart way to replace the last word after "/" with sed ...

How do I get Git's latest stable release version number?

I'm writing a git-install.sh script: http://gist.github.com/419201 To get Git's latest stable release version number, I do: LSR_NUM=$(curl -silent http://git-scm.com/ | sed -n '/id="ver"/ s/.*v\([0-9].*\)<.*/\1/p') 2 Questions: Refactor my code: Is there a better way programmatically to do this? This works now, but it's brittle: if...

sed as grep + ignore # and match

I have the following file example more somefile param=a b c d e f g z x w # param=a b c d e f g z x w I need to create with sed the following (should be one line if possible): Ignore # char in the beginning of line Match first the param string Second match the "a b c d e f g z x w" (like grep -w) and give exit stat...

sed or grep or awk to match very very long lines

more file param1=" 1,deerfntjefnerjfntrjgntrjnvgrvgrtbvggfrjbntr*rfr4fv*frfftrjgtrignmtignmtyightygjn 2,3,4,5,6,7,8, rfcmckmfdkckemdio8u548384omxc,mor0ckofcmineucfhcbdjcnedjcnywedpeodl40fcrcmkedmrikmckffmcrffmrfrifmtrifmrifvysdfn drfr4fdr4fmedmifmitfmifrtfrfrfrfnurfnurnfrunfrufnrufnrufnrufnruf"**** need to match the content of p...

one line using sed and bc together?

I want to add one to the last value at the end of a string in sed. I'm thinking along the lines of cat 0809_data.csv |sed -e 's/\([0-9]\{6\}\).*\(,[^,]*$\)/\1\2/g'| export YEARS = $(echo `grep -o '[^,]*$' + 1`|bc) e.g. 123456, kjhsflk, lksjgrlks, 2.8 -> 123456, 3.8 Would this be more reasonable/feasible in awk? ...

Optimize grep, awk and sed shell stuff

I try to sum the traffic of diffrent ports in the logfiles from "IPCop" so i write and command for my shell, but i think its possible to optimize the command. First a Line from my Logfile: 01/00:03:16 kernel INPUT IN=eth1 OUT= MAC=xxx SRC=xxx DST=xxx LEN=40 TOS=0x00 PREC=0x00 TTL=98 ID=256 PROTO=TCP SPT=47438 DPT=1433 WINDOW=16384 RES=...

Sed non greedy curly braces match

I have a string in a file a.txt {moslate}alho{/moslate}otra{moslate}a{/moslate} a need to get the string otra using sed. With this regex sed 's|{moslate}.*{/moslate}||g' a.txt a get no output at all but when i add a ? to the regex s|{moslate}.*?{/moslate}||g a.txt (I've read somewhere that it makes the regex non-greedy) i get n...