Copy input file based on condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy input file based on condition
# 1  
Old 11-09-2009
Copy input file based on condition

Hi,

I am new to unix shell programming.

I want to write a shell script for a functionality existing in mainframe system.

I have one file as below as input

123456
&__987
&12yuq
abcdef

_ referes to blank
condition:whenever the input file is having &__ ,it should be replaced with
blanks ___. rest of the file should be copied.
Other records should be copied as it is to the output file.

The output file should be as below
123456
___987
&12yuq
abcdef

Please help out with a shell script sample

Thanks
# 2  
Old 11-09-2009
something like this :

Code:
sed 's/&__/___/' input_file > output_file

# 3  
Old 11-09-2009
Thanks Panyam.
It is working but

if the input record is like this it should not convert,but it is converting.

for example

abc&__123

should be
abc&__123

but it is converted
abc___123

Basically it should convert only when & is occuring in first field.
# 4  
Old 11-09-2009
Code:
sed 's/^&__/___/' input_file > output_file

# 5  
Old 11-09-2009
Thanks Frans

It is working fine
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk to add +1 to value based on condition in input

In the awk below I am trying to add a | that will adjust $2 in the ouput by adding +1 if the original value from file that was used in $3 had a - in it. Line 3 of file is an example of this. In my current awk I just subtract one but I am not sure how to only apply this to those values without a -.... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. Shell Programming and Scripting

Copy data to new file based on input pattern

Hi All, I want to create a new file based on certain conditions and copy only those conditioned data to new file. Input Data is as it looks below. ORDER|Header|Add|32|32|1616 ORDER|Details1......... ORDER|Details2......... ORDER|Details3......... ORDER|Details4............ (10 Replies)
Discussion started by: grvk101
10 Replies

3. Shell Programming and Scripting

Copy down based on condition

Hello: I need to copy down some data from the previous record in to the next record based on the below conditions If position 41- 59 of the current record is same as the previous record and the value of position 62 is not equal to 1 then copy the previous records value for positions... (1 Reply)
Discussion started by: techedipro
1 Replies

4. Shell Programming and Scripting

extracting lines based on condition and copy to another file

hi i have an input file that contains some thing like this aaa acc aa abc1 1232 aaa abc2.... poo awq aa abc1 aaa aaa abc2 bbb bcc bb abc1 3214 bbb abc3.... bab bbc bz abc1 3214 bbb abc3.... vvv ssa as abc1 o09 aaa abc4.... azx aaq aa abc1 900 aqq abc19.... aaa aa aaaa abc1 899 aa... (8 Replies)
Discussion started by: anurupa777
8 Replies

5. Shell Programming and Scripting

How can I change file value based on condition

Hi, Gurus, I got a problem to resolve following issue: I have one file file1as following: start_dt=2010-01-01 12:00:02 start_dt=2011-01-01 09:00:02 start_dt=2009-01-01 11:00:02I have another file file2 as following: title1, 2010-01-03 10:00:02 title2, 2011-01-04 11:00:02 title3,... (5 Replies)
Discussion started by: ken002
5 Replies

6. Shell Programming and Scripting

Copy file to two folders with condition

Hello! Please, help me write this simple script using bash scripting. Task: In Folder1 I have files: name1.txt, name2.txt, name3.txt .. etc In Folder2 may located such files: name1.txt, name2.txt .. etc In Folder3 may located files like: name1.txt_abc{some_symbols}_vxz,... (6 Replies)
Discussion started by: optik77
6 Replies

7. Shell Programming and Scripting

Move input file based on condition

Hello, I have File1 in a directory A, a File2 in a directory B. If the File2 is not empty Then I have to move File1 from directory A to a directory archive Else no action. Is it possible to do this from one command line? Thank you in advance for your answers. Madi (2 Replies)
Discussion started by: AngelMady
2 Replies

8. Shell Programming and Scripting

Change in Input feed based on condition file

Sorry Guys for not being able to explain in one of my earlier post. I am now putting my requirement with the input file and desired output file. In the below input file - Transaction code is at position 31:40. Business code is from position 318:321 TSCM00000005837 ... (7 Replies)
Discussion started by: varunrbs
7 Replies

9. Shell Programming and Scripting

Awk to print on condition in input file

I need only those records which has $2 equal to "DEF" independent of case (i.e upper or lower) nawk -F"," '$2 ~ //{print $0}' file This returns 3rd record also which i dont want I tried this but this doesnt work as expected. nawk -F"," '$2 == ""{print $0}' file i dont... (3 Replies)
Discussion started by: pinnacle
3 Replies

10. Shell Programming and Scripting

Spliting file based on condition

Hi, I have a comma separated file with millions of records in it. I have a requirement to split the file based on the value in a one of the columns. Suppose i have a text file with columns like C1, C2,C3,C4 Column C4 can hold the values either 01 or 02 03 or 04. I nned to extract... (2 Replies)
Discussion started by: Raamc
2 Replies
Login or Register to Ask a Question