Editing part of the string

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Editing part of the string
# 1  
Old 07-25-2011
Editing part of the string

Hi guys got a problem here hope u all can help me. I learn that sed can actually edit a string but you need to know the old attribute to change to new 1.
 sed "s/$title:$author/$title:$Nauthor/g"

"Harry Potter - The Half Blood Prince:J.K Rowling:40.30:10:50"

Each delimiter : represent 1 new attribute.
can i change 40.30 without knowing it 40.30 but using it position to change??

Last edited by radoulov; 07-25-2011 at 10:47 AM.. Reason: Code tags.
# 2  
Old 07-25-2011
From BookDB.txt? ))) This is at least the third question for the last two days.
can i change 40.30 without knowing it 40.30 but using it position to change??
Yes, you can. If you will study good. Smilie
# 3  
Old 07-25-2011
Is it? =.= but my shell coding one/two day lesson only then assignment came!! i try my very best to learn from google.com but really cannot solve this part =( help pls !!
# 4  
Old 07-25-2011
From the command line:
$ awk -v var="YOUR PRICE" '
BEGIN { FS=OFS=":" }  
/^Harry Potter/ { $3=var }
{ print }
'  BookDB.txt

But please don't ask me how this works.
Or with sed:
$ var="YOUR PRICE"; sed -n '/^Harry Potter/s/[^:]*:/'"$var"':/3p' BookDB.txt

Last edited by yazu; 07-25-2011 at 11:22 AM.. Reason: sed variant
# 5  
Old 07-25-2011
Thank!! i will go google and learn what each symbol mean
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help regarding String editing

Hi Geeks I am working on trimming the logs and extracting the XMLs from it. I am facing one problem here. My XML String is ending with ...........Request></Body></Envelope>S/R sometimes there is more then just S/R in the end. I want to delete anything comes after </Envelope>... (3 Replies)
Discussion started by: santy00110011
3 Replies

2. Shell Programming and Scripting

Deleting part of a string : string manipulation

i have something like this... echo "teCertificateId" | awk -F'Id' '{ print $1 }' | awk -F'te' '{ print $2 }' Certifica the awk should remove 'te' only if it is present at the start of the string.. anywhere else it should ignore it. expected output is Certificate (7 Replies)
Discussion started by: vivek d r
7 Replies

3. UNIX for Dummies Questions & Answers

Help with editing string elements

Hi All I have a question. I would like to edit some string characters by replacing with characters of choice located in another file. For example in sample file>S5_SK1.chr01 NNNNNNNNNNNNNNNNNNNCAGCATGCAATAAGGTGACATAGATATACCCACACACCACACCCTAACACTAACCCTAATCTAACCCTGGCCAACCTGTTT... (9 Replies)
Discussion started by: pawannoel
9 Replies

4. Shell Programming and Scripting

Need to take one part from a string

I have a string something like "/opt/src/default.cfg" OR /opt/src/common/one This whole string stored in an array. The problem is this string is not constant and it will keep on changing as lot of strings are stored in the array and it will be look like :- case 1 /opt/src/default.cfg ... (8 Replies)
Discussion started by: Renjesh
8 Replies

5. Homework & Coursework Questions

String editing using sed? awk?

1. The problem statement, all variables and given/known data: Problem Statement for project: When an account is created on the CS Unix network, a public html directory is created in the account's home directory. A default web page is put into that directory. Some users replace or... (13 Replies)
Discussion started by: peage1475
13 Replies

6. Shell Programming and Scripting

Getting part of a string

Hi, I have a string assinged to a varaible as below. FILE=/var/adm/message If $FILE is the value where it stores the path of message file. I would like to extract the location of the file message as below LOCATION=/var/adm FILE may have value like /var/adm/xxxx/message ... (2 Replies)
Discussion started by: raghu.amilineni
2 Replies

7. Programming

Editing or Adding to ELF string tables

Is it possible to add - or edit - data (the strings) contained within the string table of an ELF executable? I know I can access the string table with the following code; while ((scn = elf_nextscn(m_elf, scn)) != 0) { char *name = 0; gelf_getshdr(scn, &shdr); ... (9 Replies)
Discussion started by: Dhodder
9 Replies

8. Shell Programming and Scripting

SH Script help. editing string

I have a string that looks like this username|field1|field2|field3 the data has a delimiter of "|" how can i edit field1, keeping the rest of the data the same also how can i edit field2 and 3. (3 Replies)
Discussion started by: nookie
3 Replies

9. Shell Programming and Scripting

string editing in files

Hi all, I'm fairly new to scripting in linux and need some help. I have an file that looks something like this: ~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Some comments # Some comments # Some comments # Some comments # Some comments # Some comments abc:/path/to/somewhere:X... (3 Replies)
Discussion started by: Avatar Gixxer
3 Replies

10. UNIX for Dummies Questions & Answers

Editing one string in multiple files

I am trying to edit multiple files from one directory and including all the files in all the sub directories. My string opens each file, puts the text on my screen and does not save the new information to the file. I am using a variable in my script, and wondering if that is what is choking it. ... (1 Reply)
Discussion started by: Skoshi
1 Replies
Login or Register to Ask a Question