Cut and paste data in new file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cut and paste data in new file
# 1  
Old 07-21-2012
Bug Cut and paste data in new file

HI Guys,

I have file A:

Code:
Abc XyZ Abc Xyz Kal Kaloo 
Abc XyZ Abc Xyz Kalpooo 
Abc XyZ Abc Xyz  Kloo 
Abc  Abc  Klooo

I want file B
Code:
Abc XyZ Abc Xyz Kal Kaloo 
Abc XyZ Abc Xyz Kalpooo 
Abc XyZ Abc Xyz  Kloo

File A is now 1 lines

Code:
Abc  Abc  Klooo

Cut all lines which have xyz and kal

Thanks
# 2  
Old 07-21-2012
Do you have the same number of columns?
If for example you have 6 columns for each line and you want to separate those which are different in columns 2 and 5 you can use this script:

Code:
awk '{close(f);f=$2 OFS $5}{print > f".txt"}' input.txt

input:
Code:
Abc XyZ Abc Xyz Kal Kaloo 
Abc XyZ Abc Xyz Kal pooo 
Abc XyZ Abc Xyz Kal oo 
Abc XYz Abc Xyz Kl ooo

outputs:
-XyZ Kal.txt :
Code:
Abc XyZ Abc Xyz Kal Kaloo 
Abc XyZ Abc Xyz Kal pooo 
Abc XyZ Abc Xyz Kal oo

-XyZ Kl.txt :
Code:
Abc XyZ Abc Xyz Kl ooo

Be aware that it creates as many files as you have variants based on your 2nd and 5th columns.
# 3  
Old 07-21-2012
Maybe I don't get the problem, but I would simply use grep:

Code:
grep -vi "xyz" fileA | grep -vi kal > fileB

The -i is for "case insensitive" because you didn't use capitals in "cut all lines which have xyz and kal". You can also combine the two calls into one using disjunction, and do much, much more with grep (see the man page).
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

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

3. Shell Programming and Scripting

Issue with cut and paste

let i have A file and B file A has contains 4 fields as below ---------------- f1 f2 f3 f4 B file consists of 5 fields as below -------------------- f5 f6 f7 f8 f9 need to display as below output: f5 f1 f3 f8 f9 (2 Replies)
Discussion started by: ANSHUMAN1983
2 Replies

4. 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

5. 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

6. UNIX for Dummies Questions & Answers

Cut paste from one file to other

Hello, I am working on unix for the first time. I have to write a shell script where i want to cut paste from one file to other. File "1234.abc" is 03,12345555 16,936,x,x,120 16,936,x,x,100 49,12345555 03,12347710 16,936,x,x,115 16,936,x,x,122 49,12347710 03,12342222... (9 Replies)
Discussion started by: swapsb
9 Replies

7. Shell Programming and Scripting

Cut and paste data in matrix form

I have large formatted data file with five columns. This has to be rearranged in lower order matrix form as shown below for sample data. 1 2 3 4 5 1.0 3.0 2.0 5.0 3.0 2.0 4.0 3.0 1.0 6.0 2.0 3.0 4.0 5.0 1.0 1.0 4.0 2.0 3.0 5.0 3.0 5.0 4.0 2.0 8.0 1.0 3.0 2.0 4.0 5.0 2.0... (7 Replies)
Discussion started by: dhilipumich
7 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 and paste using awk

Hi i need a favour i have a file which has some trillions of records. The file is like this 11111000000000192831840914000000000000000000000000000 45789899090000000000000000011111111111111111111111111 I want to cut specific postions in each line like cut1-3 and assisgn it to a variable and... (5 Replies)
Discussion started by: richa2.m
5 Replies
Login or Register to Ask a Question