Help Using Sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help Using Sed
# 1  
Old 09-25-2008
Help Using Sed

SmilieSmilieSmilieSmilie

Immediately following is a line of text that I wish to run through sed to have a couple things changed.

MSCT HATR/sgf-v1_1-3010-20080510-200727.dx* -> UDP 127.0.0.1

Using a script with sed ive been trying to get the letters "HATR" to be whatever I decide by using a "$1" after the script name when i start the script with no luck. I would also like to take the 4 digits that appear immediately after the "sgf-v1_1-" and alter the first digit from a 3 to a 6 and place it with a blank space after the last number in the line. So if I named this script alter and I had multple lines to ammend like the one above I would type

alter 25SEPTHATR and it would give me the following out:

MSCT 25SEPTHATR/sgf-v1_1-3010-20080510-200727.dx* -> UDP 127.0.0.1 6010
MSCT 25SEPTHATR/sgf-v1_1-3010-20080610-200727.dx* -> UDP 127.0.0.1 6010
MSCT 25SEPTHATR/sgf-v1_1-3011-20080510-200727.dx* -> UDP 127.0.0.1 6011
MSCT 25SEPTHATR/sgf-v1_1-3011-20080610-200727.dx* -> UDP 127.0.0.1 6011

Can anyone show me how Ive already done alot with sed to get the chages to this point just cant figure these last couple out?

SmilieSmilieSmilie

Last edited by Franklin52; 09-25-2008 at 10:13 AM.. Reason: e-mail address removed
# 2  
Old 09-25-2008
post your script so far, and input example + output example
# 3  
Old 09-25-2008
well - I assume this is close to what your after ....

Code:
#   echo "MSCT HATR/sgf-v 1_1-3010-20080510-200727.dx* -> UDP 127.0.0.1" | sed 's/\(.*sgf-v 1_1-\)\(.\)\(...\)\(.*\)/\1\2\3\4 6\3/g'
MSCT HATR/sgf-v 1_1-3010-20080510-200727.dx* -> UDP 127.0.0.1 6010


Last edited by Tytalus; 09-25-2008 at 10:31 AM.. Reason: minor typo...
# 4  
Old 09-25-2008
Another one:
Code:
#!/bin/sh

awk -F" |/" -v var=$1 '{$2=var;split($3,a,"-");$NF=$NF" "a[3]+3000}{print}' file

Save this script as alter, make it executable and start the script as follow:

Code:
./alter 25SEPTHATR

Regards

Last edited by Franklin52; 09-25-2008 at 01:47 PM.. Reason: typo name variable
# 5  
Old 09-25-2008
Hammer & Screwdriver Thank You all

Either one worked out well I appreciate you guys providing me an answer so quickly. I posted one more question concerning sed in the Shell Programming and Scripting Forum where this one was. If you could help me with that it would complete my task at hand...thanks in advance.

SmilieSmilieSmilieSmilieSmilieSmilieSmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I am learning regular expression in sed,Please help me understand the use curly bracket in sed,

I am learning SED and just following the shell scripting book, i have trouble understanding the grep and sed statement, Question : 1 __________ /opt/oracle/work/antony>cat teledir.txt jai sharma 25853670 chanchal singhvi 9831545629 anil aggarwal 9830263298 shyam saksena 23217847 lalit... (7 Replies)
Discussion started by: Antony Ankrose
7 Replies

2. Shell Programming and Scripting

sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi, I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :- ./sample.sh: line... (12 Replies)
Discussion started by: satishmallidi
12 Replies

3. Shell Programming and Scripting

sed inside sed for replacing string

My need is : Want to change docBase="/something/something/something" to docBase="/only/this/path/for/all/files" I have some (about 250 files)xml files. In FileOne it contains <Context path="/PPP" displayName="PPP" docBase="/home/me/documents" reloadable="true" crossContext="true">... (1 Reply)
Discussion started by: linuxadmin
1 Replies

4. Shell Programming and Scripting

How to use sed to replace the a string in the same file using sed?

How do i replace a string using sed into the same file without creating a intermediate file? (7 Replies)
Discussion started by: gomes1333
7 Replies

5. UNIX for Dummies Questions & Answers

SED: Can't Repeat Search Character in SED Output

I'm not sure if the problem I'm seeing is an artifact of sed or simply a beginner's mistake. Here's the problem: I want to add a zero-width space following each underscore between XML tags. For example, if I had the following xml: <MY_BIG_TAG>This_is_a_test</MY_BIG_TAG> It should look like... (8 Replies)
Discussion started by: rhetoric101
8 Replies

6. Shell Programming and Scripting

deleting text records with sed (sed paragraphs)

Hi all, First off, Thank you all for the knowledge I have gleaned from this site! Deleting Records from a text file... sed paragraphs The following code works nearly perfect, however each time it is run on the log file it adds a newline at the head of the file, run it 5 times, it'll have 5... (1 Reply)
Discussion started by: Festus Hagen
1 Replies

7. Shell Programming and Scripting

sed has zeored my files. Help me with sed please

i made a script to update a lot of xml files. to save me some time. Ran it and it replaced all the the files with a 0kb file. The problem i was having is that I am using sed to change xml node <doc_root>. The problem with this is it has a / in the closing xml tag and the stuff inside will also have... (4 Replies)
Discussion started by: timgolding
4 Replies

8. Shell Programming and Scripting

sed over writes my original file (using sed to remove leading spaces)

Hello and thx for reading this I'm using sed to remove only the leading spaces in a file bash-280R# cat foofile some text some text some text some text some text bash-280R# bash-280R# sed 's/^ *//' foofile > foofile.use bash-280R# cat foofile.use some text some text some text... (6 Replies)
Discussion started by: laser
6 Replies

9. Shell Programming and Scripting

Issue with a sed one liner variant - sed 's/ ; /|/g' $TMP1 > $TMP

Execution of the following segment is giving the error - Script extract:- OUT=$DATADIR/sol_rsult_orphn.bcp TMP1=${OUT}_tmp1 TMP=${OUT}_tmp ( isql -w 400 $dbConnect_OPR <<EOF select convert(char(10), s.lead_id) +'|' + s.pho_loc_type, ";", s.sol_rsult_cmnt, ";", +'|'+ s.del_ind... (3 Replies)
Discussion started by: kzmatam
3 Replies

10. Shell Programming and Scripting

Sed Question 1. (Don't quite know how to use sed! Thanks)

Write a sed script to extract the year, rank, and stock for the most recent 10 years available in the file top10_mktval.csv, and output in the following format: ------------------------------ YEAR |RANK| STOCK ------------------------------ 2007 | 1 | Exxon... (1 Reply)
Discussion started by: beibeiatNY
1 Replies
Login or Register to Ask a Question