Cut paste from one file to other


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Cut paste from one file to other
# 8  
Old 01-07-2011
Scrutinizer,

Quote:
Originally Posted by Scrutinizer
Code:
 var=047377710;sed -n "/^03,$var/,/^49,/p" infile > newfile

your code works fine and creates new file with desired records.
but i want those records to be deleted from the infile.

kindly reply
# 9  
Old 01-07-2011
Try:
Code:
var=047377710;sed -n "/^03,$var/,/^49,/{p;d;};woutfile" infile > newfile

outfile should contain the original with the records removed.
# 10  
Old 02-03-2011
The client has come up with new requirement in this.
He wants to copy lines starting with numbers 01, 02, 98 and 99 to the newly created file.

original file tst.abc
Code:
01,,BNZA,101103,0400,1,78,78/
02,BNZA,084-004,1,101102,0000/
03,047316555,AUD,015,000,100,11164907,102,100,400/
88,11164907,402,500,500,000,501,000,502/
88,000,503,000,965,000,966,400/
88,967,000,968,000,969,000/
16,930,11164907,0,0,FROM: 04-737-7577
16,475,60000,0,0046887/
16,501,6512446,0,0,FD000004793
16,501,3719353,0,0,002150010544
16,501,632224,0,0,002150010742
16,501,240884,0,0,002150010741
49,44660628,44660228/
03,047374624,AUD,015,000,100,000,102,000,400/
88,000,402,000,500,000,501,000,502/
88,000,503,000,965,000,966,400/
88,967,000,968,000,969,000/
49,400,000/
03,047377710,AUD,015,000,100,86840225,102,13100,400/
88,86840225,402,5900,500,000,501,000,502/
88,000,503,000,965,000,966,400/
88,967,000,968,000,969,000/
16,915,91695,0,000000000002/
16,915,228465,0,000000000009/
16,915,6955,0,000000000011/
16,915,106620,0,000000000013/
16,915,41830,0,000000000016/
16,915,224650,0,000000000017/
16,915,112085,0,000000000019/
16,915,25750,0,000000000049/
16,915,8440,0,000000000059/
16,915,81200,0,000000000081/
16,915,114480,0,000000000086/
49,347380300,347379900/
98,1058972775,3,1058972775/
99,1898953341,1,272,1898948248/

if i want account no 047316555 to be seperated out, then
new file tst.6555
Code:
01,,BNZA,101103,0400,1,78,78/
02,BNZA,084-004,1,101102,0000/
03,047316555,AUD,015,000,100,11164907,102,100,400/
88,11164907,402,500,500,000,501,000,502/
88,000,503,000,965,000,966,400/
88,967,000,968,000,969,000/
03,047316555,AUD,015,000,100,11164907,102,100,400/
88,11164907,402,500,500,000,501,000,502/
88,000,503,000,965,000,966,400/
88,967,000,968,000,969,000/
16,930,11164907,0,0,FROM: 04-737-7577
16,475,60000,0,0046887/
16,501,6512446,0,0,FD000004793
16,501,3719353,0,0,002150010544
16,501,632224,0,0,002150010742
16,501,240884,0,0,002150010741
49,44660628,44660228/
98,1058972775,3,1058972775/
99,1898953341,1,272,1898948248/

and tst.new
Code:
01,,BNZA,101103,0400,1,78,78/
02,BNZA,084-004,1,101102,0000/
03,047374624,AUD,015,000,100,000,102,000,400/
88,000,402,000,500,000,501,000,502/
88,000,503,000,965,000,966,400/
88,967,000,968,000,969,000/
49,400,000/
03,047377710,AUD,015,000,100,86840225,102,13100,400/
88,86840225,402,5900,500,000,501,000,502/
88,000,503,000,965,000,966,400/
88,967,000,968,000,969,000/
16,915,91695,0,000000000002/
16,915,228465,0,000000000009/
16,915,6955,0,000000000011/
16,915,106620,0,000000000013/
16,915,41830,0,000000000016/
16,915,224650,0,000000000017/
16,915,112085,0,000000000019/
16,915,25750,0,000000000049/
16,915,8440,0,000000000059/
16,915,81200,0,000000000081/
16,915,114480,0,000000000086/
49,347380300,347379900/
98,1058972775,3,1058972775/
99,1898953341,1,272,1898948248/

Kindly help

Last edited by swapsb; 02-03-2011 at 06:45 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to cut a pipe delimited file and paste it with another file to form a comma separated outputfile

Hello ppl I have a requirement to split (cut in unix) a file (A.txt) which is a pipe delimited file into A1.txt and A2.txt Now I have to join (paste in unix) this A2.txt with external file A3.txt to form output file A4.txt which should be CSV (comma separated file) so that third party can... (25 Replies)
Discussion started by: etldev
25 Replies

2. Shell Programming and Scripting

Problem in cut or paste

Hello, I have some problem in cut or paste command for my text data. Input1.txt : I use cut command : cut -d ' ' -f1 Input1.txt > result.txt result.txt : Then, I use paste command to merge result.txt. paste -d ' ' result.txt Input1.txt > output.txt output.txt showed : I use cut... (1 Reply)
Discussion started by: awil
1 Replies

3. Shell Programming and Scripting

Cut, replace and Paste a String from one file to another

I need to cut all the Strings in one file and Paste it in the another file in the Specific line by replacing the specific String. For Example Step 1: From the newfile.txt, i need to copy all the strings newfile.txt How are you, I am fine, How is your work newfle2.txt Hello david,... (2 Replies)
Discussion started by: Padmanabhan
2 Replies

4. Shell Programming and Scripting

Cut and paste data in new file

HI Guys, I have file A: Abc XyZ Abc Xyz Kal Kaloo Abc XyZ Abc Xyz Kalpooo Abc XyZ Abc Xyz Kloo Abc Abc Klooo I want file B Abc XyZ Abc Xyz Kal Kaloo Abc XyZ Abc Xyz Kalpooo Abc XyZ Abc Xyz Kloo File A is now 1 lines Abc Abc Klooo Cut all lines which have xyz... (2 Replies)
Discussion started by: asavaliya
2 Replies

5. Shell Programming and Scripting

Help required the cut the whole contents from one file and paste it into new file

Hi, First of all sincere apologies if I have posted in a wrong section ! Please correct me if I am wrong ! I am very new to UNIX scripting. Currently my problem is that I have a code file at the location /home/usr/workarea/GeneratedLogs.log :- Code :- (Feb 7, 571 7:07:29 AM),... (4 Replies)
Discussion started by: acidburn_007
4 Replies

6. Shell Programming and Scripting

need help with cut and paste command

I have a file which contains 3 fields separated by tabs example andrew kid baker I need to swap kid and baker using cut and paste commands how is this to be done? Thanks (3 Replies)
Discussion started by: drew211
3 Replies

7. UNIX for Dummies Questions & Answers

Need help with using cut and paste command

I have a file which contains 3 fields separated by tabs example andrew kid baker I need to swap kid and baker using cut and paste commands how is this to be done? Thanks (1 Reply)
Discussion started by: drew211
1 Replies

8. Shell Programming and Scripting

cut and paste

Hi, Need a help with shell script. I have to search for a string in one of the file, if match found, copy the line to a new file and delete the line from the exisiting file. eg: 83510000000000063800000.1800000.1600000.1600000.2400000.1800000.2000000.21... (6 Replies)
Discussion started by: gpaulose
6 Replies

9. Shell Programming and Scripting

cut and paste?

hi, I have a file with content like this for an employee: EmployeeID 101 Day_type, day vacation,1/2/2009 sick day, 3/2/2009 personal day, 4/5/2009 jury duty day, 5/5/2009 how do I make the result to show: EmployeeID,Day_type,day 101,vacation,1/2/2009 101,sick day,... (6 Replies)
Discussion started by: jbchen
6 Replies

10. Shell Programming and Scripting

cut & paste

hi i am new to shell scripting, i have been trying to cut columns numbered 1,4 of a file consisiting of 4 columns. Each column is seperated by 2 spaces. for example: john 6102097199 tennessee usa michel 6734590899 texas USA now, i need to cut the name... (3 Replies)
Discussion started by: t_harsha18
3 Replies
Login or Register to Ask a Question