How to copy one file into another except some text


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to copy one file into another except some text
# 1  
Old 08-25-2011
Question How to copy one file into another except some text

I have file input like-
Code:
abc,"123",""123","123","123","123","123","123","123","123","123","123","123","123",
abc,"123","123","123","123","123","123","123","123","123""123",abc etc

Input file consists of 1000 records and i want to copy into final file except abc
abc is at fixed position like 1,17,33,49 etc in short 1, (1+16) , (1+16+16) ,etc
How to do this, in efficient way using scripting??Smilie
Required output file:-
Code:
"123",""123","123","123","123","123","123","123","123","123","123","123","123"

Moderator's Comments:
Mod Comment This thread is not AIX specific, moving it to shell scripting area. Please use [code] and [/code] tags when posting code, data or logs etc. to preserve formatting and enhance readability, thanks.

Last edited by zaxxon; 08-25-2011 at 02:49 AM.. Reason: code tags
# 2  
Old 08-25-2011
It works,

Code:
 
sed -e 's/,abc/#/g' -e 's/abc,/#/g' -e 's/#//g' inputfile > outputfile


Last edited by itkamaraj; 08-25-2011 at 03:13 AM..
# 3  
Old 09-06-2011
How to minimize the awk operation???

cat abc.csv | awk -F"," '{ print $1","$2","$3","$4","$5","$6","$7","$8","$9","$10","$11","$12","$13","$14","$15","$16", "$18","$17 }' > xyz.csv
i want to copy first 16 field and then 17,18 field.

Is any other efficient way to minimize the above awk operation?Smilie
# 4  
Old 09-06-2011
See if this works for you :
Code:
awk 'BEGIN { FS=","; OFS="," } { printf $16","$17","$18; for (i=1;i<=15;i++) printf $i"," }' abc.csv | sed "s/,$//g" > xyz.csv

# 5  
Old 09-06-2011
What is your record? How many fields in it? When you say about positions what do you mean?
# 6  
Old 09-06-2011
How to minimize awk ?

Code:
cat abc.csv | awk -F"," '{ print  $1","$2","$3","$4","$5","$6","$7","$8","$9","$10","$11","$12","$13","$14","$15","$16",   "$18","$17 }' > xyz.csv

Input file: abc.csv contains 18 fields which are comma separated.
Output: xyz.csv file contains all those fields only difference in position of 17 and 18 such as 1,.....,16,17,18.
How to do in efficient way??

---------- Post updated at 06:37 PM ---------- Previous update was at 06:31 PM ----------

Input file content:
123,abc,345
123,abc,345
234,fgb,435
234,fgb,435
234,fgb,435
234,fgb,435

Output file content:
File 1 content: (Process only one record)
123,abc,345
234,fgb,435

File 2 Content(Reject File contain rest of the record):
123,abc,345
234,fgb,435
234,fgb,435
234,fgb,435


Concept:
Actually out of multiple same record i want to process only one record and move rest of record to reject file.How to perform reject file concept.??Smilie

Last edited by radoulov; 09-06-2011 at 10:07 AM.. Reason: Code tags!
# 7  
Old 09-06-2011
???
Code:
awk 'BEGIN { FS = OFS = ","} { t = $17; $17=$18; $18=t; print }'

Well, you ask one question in the original post, then another, and now third... (((
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy text from web page and add to file

I need help to make a script for Ubuntu to OSCam that copy the text on this website that only contains "C: ip port randomUSERNAME password" and want to exclude the text "C:" and replace the rest with the old in my test.server file. (line 22) device = ip,port (line 23) user =... (6 Replies)
Discussion started by: baxarn
6 Replies

2. Shell Programming and Scripting

Copy text and create new file

I have a directory with ~500 files that look like below. I need to copy each unique entry up until the second_ only once and put a .txt in place of the _. I am not quite sure how but have the below as a startThank you :). cp -u file1.txt "$(cat output.txt)" file1.txt ... (4 Replies)
Discussion started by: cmccabe
4 Replies

3. UNIX for Dummies Questions & Answers

Hoe to copy selected strings from file into another text file

Hi Experts, I just want to copy some selected strings from a a file into a new .txt file . I am using below command to find the data now want to copy the search results into another .txt file please help me . find /Path -exec grep -w "filename1|filename1|filename1|" '{}' \;... (2 Replies)
Discussion started by: mumakhij
2 Replies

4. Shell Programming and Scripting

Copy selective lines from text file

Hello, I have a text file which I need to check for presence of certain tags, and then copy a subsequent portion of text into another file. The tag matching canbe done with Grep but I do not know how to copy selective lines from one file to another. Is it possible do that? I checked up some... (8 Replies)
Discussion started by: ajayram
8 Replies

5. Homework & Coursework Questions

copy files inside a text file

Hi Guys , I am new to this and Hi to all ,Need your help I am trying to copy Files which are inside file.txt The files inside file.txt are inthe below order file1.log file2.log file3.log ....... I want to copy these files to an output Directory , Please help (1 Reply)
Discussion started by: hc17972
1 Replies

6. Homework & Coursework Questions

copy files inside a text file

Hi Guys , I am new to this and Hi to all ,Need your help I am trying to copy Files which are inside file.txt The files inside file.txt are inthe below order file1.log file2.log file3.log ....... I want to copy these files to an output Directory , Please help (1 Reply)
Discussion started by: hc17972
1 Replies

7. Shell Programming and Scripting

How to copy text with ed to new file ?

Alright, so in ed i do a subsititution: ed file << 'HERE' s/.*h2.*>\(.*\)<.*/\1/p HERE This gives me my desired line: Errors found while checking this document as XHTML 1.0 Transitional! But how would i put this line in a temporary file ? (4 Replies)
Discussion started by: Bertieboy7
4 Replies

8. UNIX for Dummies Questions & Answers

Shell script to search for text in a file and copy file

Compete noob question.... I need a script to search through a directory and find files containing text string abcde1234 for example and then copy that file with that text string to another directory help please :eek: (9 Replies)
Discussion started by: imeadows
9 Replies

9. UNIX for Advanced & Expert Users

How to copy a string to a text file

I am using the following command to email a tex file as an attachment- cat mailtext.txt | elm -s "Subject" emailAddr where content of mailtext.txt is - "Body of email" This will attach foo.txt with the email. My problem is that the file foo.txt is ceated dynamically everytime with a... (5 Replies)
Discussion started by: hpuxlxboy
5 Replies

10. UNIX for Dummies Questions & Answers

I want to copy the text output from a 'nohup.out' file.

Hello, I have a nohup.out file that, when executed, outputs a spreadsheet file with four-to-seven columns of number. I want to copy this output (in its entirety), so that I could then paste it on excel@ , or Notepad@. Please help, thanks. (3 Replies)
Discussion started by: Iamthe great
3 Replies
Login or Register to Ask a Question