Find and Replacement


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Find and Replacement
# 1  
Old 09-01-2005
Find and Replacement

Hi,

Im new to this forum, and also to Unix.

I have a requirement like this.

i have one DAT file that contains data as follows,

EMPNAME,
DEPT,
SALARY,
JOIN_DT,
DEDUCTION

i have one configuration file that contains data as follows,

SALARY
BONUS
DEDUCTION


i want a command that changes my DAT file as follows

EMPNAME,
DEPT,
0,
JOIN_DT,
0

i want a command the modifies the DAT file based on the configuration file.

Thanks in Advance
# 2  
Old 09-01-2005
Use for (as for word in file) to get data one by one from configuration file ( if u have some delimiter , or \n then u can also use grep line by line ) and after u get the data use sed with substitute option.

For detail look into sed man page.
# 3  
Old 09-01-2005
Can you tell me the syntax of the command for this solution

Quote:
Originally Posted by Rakesh Ranjan
Use for (as for word in file) to get data one by one from configuration file ( if u have some delimiter , or \n then u can also use grep line by line ) and after u get the data use sed with substitute option.

For detail look into sed man page.
# 4  
Old 09-01-2005
Could you show us how your configuration would look like ?

From what I understand

SALARY
BONUS
DEDUCTION

is the pattern of the configuration file. How does the configuration file with real data ?

Is it like this ?

Code:
0
10
0

or

Code:
SALARY=0
BONUS=10
DEDUCTION=0

vino
# 5  
Old 09-01-2005
Thanks for responding

My configuration file will have one column and multiple rows. like this

SALARY
DEDUCTION
BONUS



Quote:
Originally Posted by vino
Could you show us how your configuration would look like ?

From what I understand

SALARY
BONUS
DEDUCTION

is the pattern of the configuration file. How does the configuration file with real data ?

Is it like this ?

Code:
0
10
0

or

Code:
SALARY=0
BONUS=10
DEDUCTION=0

vino
# 6  
Old 09-01-2005
I still dont know how your actual configuration files looks like. It would be better if you provide an actual sample of how it looks like.

In the mean time see if this suits you

Code:
[/tmp]$ echo "EMPNAME,
DEPT,
SALARY,
JOIN_DT,
DEDUCTION" | sed -e 's/SALARY/0/g' -e 's/DEDUCTION/0/g'
EMPNAME,
DEPT,
0,
JOIN_DT,
0

Vino
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Is this MB, which needs replacement ?

Hello, I am getting below error in fmadm output. This server is not in support, so can't reach them. Is it showing that motherboard is faulty and should be replaced ? It was rebooted a week back and then, there were no errors # fmadm faulty --------------- ------------------------------------ ... (1 Reply)
Discussion started by: solaris_1977
1 Replies

2. Shell Programming and Scripting

Busybox search replacement for find

Hi, I am looking for a solution to find files in a folder and subfolders. Those files should be moved (some with spaces) when they were between 2015 Feb. 03 and 2014 Nov. 24. find . -type f -newermt "2010-01-01" ! -newermt "2010-06-01" I am working on a QNAP with a small busybox.... (2 Replies)
Discussion started by: krischeu
2 Replies

3. Shell Programming and Scripting

Need help on find and replacement on specific line and position

I have a file with 100 lines. On 50 th line , from position 5 to rest of the data , I need to change the occurrence of A to B and Occurrence of M to N. Input file : Line1 Line2 Line3 -- -- 12345ABCDEFM --- -- Line 100 Output Line1 Line2 (40 Replies)
Discussion started by: Rajesh_us
40 Replies

4. Shell Programming and Scripting

File Replacement Help

Hi all, I have two files, one is a base file and the other is a dependency file. I need to replace a section in the base file (File A) with a section from the dependency file (File B), for example: File A: ... <TagName> <TagA>MyBaseFile</TagA> <TagB>MyBaseFileID</TagB> </TagName>... (5 Replies)
Discussion started by: muay_tb
5 Replies

5. UNIX for Dummies Questions & Answers

replacement

my filename.txt looks like this: 2079951061790 SCK0000891539000000000000021600R 2079951061790 SCK0000901487000000000000028900R 2079951061790 SCK0000903092000000000000021300R 2079951074758 ... (9 Replies)
Discussion started by: tjmannonline
9 Replies

6. Shell Programming and Scripting

help me :replacement

Hi pls help me for below; i have a file .content is : =================== uid,pcsPricingPlan,refPcsQosProfName 821910002022,smartlimit,SGSNQOS1 i have to replace the value of uid and pricingplan by a unix script. may be the value would be next line or any where in the file. pls... (9 Replies)
Discussion started by: Aditya.Gurgaon
9 Replies

7. Solaris

LTO replacement

Hi guys, I've changed the LTO3 device, but the OS (Solaris10) doesn't feel it. From the ok> prompt i've launched the probe-scsi-all command and it worked fine because i could see the new device; the from the ok> i booted the system (normal boot, probably a boot -r could be better..) and from... (11 Replies)
Discussion started by: cecco16
11 Replies

8. UNIX for Advanced & Expert Users

sysinfo replacement?

What is everyone using as a multi-platform replacement for "sysinfo" (licensing required nowadays)? (3 Replies)
Discussion started by: kickslop
3 Replies

9. Shell Programming and Scripting

Replacement of string

Hi I have a text file which contains the following. AAA,BBB,CCC,DDD AAA,BBB,CCC,DDD AAA,BBB,CCC,DDD How can I replace all CCC with 888, with other contents inside the file remain unchange? Please advice Desired output: AAA,BBB,888,DDD AAA,BBB,888,DDD AAA,BBB,888,DDD (1 Reply)
Discussion started by: c0384
1 Replies

10. UNIX for Dummies Questions & Answers

Regarding Replacement

I have two files: file1: somedata <html> <head> This is sample statement ...... ...... </head> </html> somedata file2: olga 81 91 B A rene 82 92 B A zack 83 93 Expextd Result: (2 Replies)
Discussion started by: rajx
2 Replies
Login or Register to Ask a Question