How i can `sed` save pattern matches to variables and do something with it? eg $ echo "string_4.3.2" | sed 's/^string_\([0-9]\)\.\([0-9]\)\.\([0-9]\)$/\1 \2 \3/' output "4 3 2" but I want to pass variables to function eg do_something() { echo $1 echo $2 echo $3 # ..... # ..... } string="string_4.3.2" if [[ $string =~ `sed ??????` ]]; then do_something "$1" "$2" "$3" fi Matched numbers need pasing to method "do_something"

Member Avatar
Member Avatar
+0 forum 1

`grep -v "#EXTINF:" All.m3u | sed 's#../##'g` I'm using the line above to try and make the playlists that I export from Banshee compatible with my digital music player. When I run the sed portion of this script I'm trying to remove the portion of the path up to where the music directories actually start. I jus want the .m3u file to be a list of lines containing Artists/Album/Title.flac But when I run this script it's removing all of the forward slashes /, not just the beginning ../ Can anyone tell me why it's removing all of the forward slashes …

Member Avatar
Member Avatar
+0 forum 1

Hello, I am trying to create a script that will compare one word at a time from one file to every word in a second file. I know how to design nested for loops to read the first entry in file1 and compare it to every entry in file2, so that's no problem. file1 contains entries that have non-alpha characters at the beginning of each line with either a single word or two words. file2 contains lines that are multiple words in length. file1 contains: 12/3:word 45/6:word word 78/9:word 01/23:word word and so on... I can design a regex that …

Member Avatar
Member Avatar
+0 forum 4

sed - need to replace only the chars or symbol after 1st and 2nd dot(.) with "int1" and "int2" respectively. Here is what I have tried but it replaces the strings in other lines. End result should look like - A.**int1**.**int2**.any.string.here sed -e 's/*/int1/' -e 's/*/int2/' -e 's/ABCD/int1/' filename A.*.*.ABCD.DEFG.HIJK A.*.ABCD.EFGH.IJKL A.ABCD.*EFGH.JKLM

Member Avatar
Member Avatar
+0 forum 1

I have a shell script that is outputting from a database. What is coming from the DB is this: ----------- 50 (1 rows affected) The issue that I have is there is an if statement in my script that looks at the first line and reads the number there. Unfortunately because of how this comes out it reads either the blank line or the hyphen as an invalid character and throws an error. I know you can use SED to remove unwanted text and spaces however I'm not sure exactly how to put it together in this instance. I do …

Member Avatar
Member Avatar
+0 forum 1

can some body expaly me this command [CODE]sed -e 's/<[^>]*>//g' test > test.t [/CODE] thank you

Member Avatar
Member Avatar
+0 forum 2

Hi Everyone, I need a replace a string (ex : this) with the string (ex : that) in each line of a file (sample.txt) using a C Shell Script and I am not allowed to use sed,awk and replace command in the unix , So i tried to use tr but it is replacing the character-by-character so if want anyone to help in with these. Thanks in advance. Thanks Srikanth M.

Member Avatar
Member Avatar
+0 forum 9

I'm trying to write a bash script that converts html file into latex file by processing each line with sed. I'm stuck with following issue: I need to replace [ICODE]<a name="[I]something[/I]">[/ICODE] with [ICODE]\index{[I]something_else[/I]}[/ICODE]. I have an associative array with key-value pairs like this: [ICODE]"[I]something[/I]" => "[I]something_else[/I]"[/ICODE]. However, there are 2 catches: [LIST=1] [*]Not all strings from [ICODE]<a>[/ICODE] tags are present. If I don't find an array element with [ICODE]"[I]something[/I]"[/ICODE] key I need to skip creation of [ICODE]\index{}[/ICODE]. [*]Some lines contain more than one occurrence of [ICODE]'<a name="...">'[/ICODE]. [/LIST] Any suggestions?

Member Avatar
Member Avatar
+0 forum 2

y/A-Za-z/N-ZA-Mn-za-m/; it is a rot13 script but I don't undestand how it works, what is the y// operator for

Member Avatar
Member Avatar
+0 forum 1

Greetings. I am using SED to cleanup files that are laid out like so: [icode] ReceiverID=028936004663 SerialNumber=WD-WCAV95708405 Currenttemp=44C PowerOnHours=3663h ReceiverID=028923894902 SerialNumber=WD-WCAV9A766701 Currenttemp=49C PowerOnHours=2215h [/icode] My boss wants files like this one to be tab ("\t") delimited like so [icode] ReceiverID=...(tab)SerialNumber=...(tab)Currenttemp=...(tab)PowerOnHours=...(newline) ReceiverID=...(tab)SerialNumber=...(tab)Currenttemp=...(tab)PowerOnHours=...(newline)... [/icode] 1) first, I added a newline to mark each record [icode]sed -i 's/h/h\n/g' infile[/icode], 2) then, I added the the tab delimiter [icode] sed -i '/.$/N; s/.\n/\t/' infile[/icode] It works but strangely, not everywhere. This is the output I get [icode] ReceiverID=...(tab)SerialNumber=...(tab???) Currenttemp=...(tab)PowerOnHours=...(newline) ReceiverID=...(tab)SerialNumber=...(tab???) Currenttemp=...(tab)PowerOnHours=...(newline) [/icode] What am I missing?? I welcome your input. Thanks.

Member Avatar
Member Avatar
+0 forum 2

The End.