Copy a part of file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Copy a part of file
# 1  
Old 10-20-2011
Copy a part of file

Hi,

I want to copy text between expressions ">bcr1" and ">bcr2" to another file.
Any simple solutions?

Thanks
# 2  
Old 10-20-2011
If all you want is the lines that have both >bcr1 and >bcr2, and then only the text between, this will work:

Code:
sed '/>bcr1.*>bcr2/ {s/.*>bcr1//; s/>bcr2.*//; b; }; d' <input-file

# 3  
Old 10-20-2011
actually, i want the text between these two expressions, not including ">bcr2" .
so if the file is
>bcr0sdfsfsfsfdfdsf>bcr1abbbbbbbbbbbbbbbbbbbsbsbsbsbsbbsbsbsbsbsb>bcr2hhhhd
>bcr3rgregergreegregererg

then i want
>bcr1abbbbbbbbbbbbbbbbbbbsbsbsbsbsbbsbsbsbsbsb

---------- Post updated at 06:55 PM ---------- Previous update was at 06:35 PM ----------

it looks like the following code works. Thanks,

Quote:
sed -n '/>bcr1/,/>bcr2/p' < infile > outfile
# 4  
Old 10-20-2011
Quote:
Originally Posted by alpesh

it looks like the following code works. Thanks,
Code:
sed -n '/>bcr1/,/>bcr2/p' < infile > outfile

Interesting, your sed programme doesn't do it for me.

Revision of my suggestion to include the leading >bcr1 should you also have problems:

Code:
sed '/>bcr1.*>bcr2/ {s/.*>bcr1/>bcr1/; s/>bcr2.*//; b; }; d'

# 5  
Old 10-20-2011
I am getting a blank output with your command , also in the output I would like to wrap the text, limit the text to 80 characters per line except the first line which is >bcr1 and the last line.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to make a loop to read the input from a file part by part?

Hi All, We've a VDI infrastructure in AWS (AWS workspaces) and we're planning to automate the process of provisioning workspaces. Instead of going to GUI console, and launching workspaces by selecting individual users is little time consuming. Thus, I want to create them in bunches from AWS CLI... (6 Replies)
Discussion started by: arun_adm
6 Replies

2. Shell Programming and Scripting

Help in UNIX shell to copy part of file name to new file name

Hi, I want to do the following in a Unix shell script and wonder if someone could assist me? I want to take files in a specific directory that start with the name pxpur012 and copy them to the same directory with the file name not containg pxpur012. For example, I have files like... (4 Replies)
Discussion started by: lnemitz
4 Replies

3. Shell Programming and Scripting

Copy part of file between two strings to another

I am a newbie to shell scripting I have a large log file , i need to work on the part of the log file for a particular date. Is there a way to find the first occurance of the date string and last occurance of the next day date date string and move this section to a new file. to explain it... (3 Replies)
Discussion started by: swayam123
3 Replies

4. Shell Programming and Scripting

[Solved] Printing a part of the last line of the specific part of a file

Hi, I have 80 large files, from which I want to get a specific value to run a Bash script. Firstly, I want to get the part of a file which contains this: Name =A xxxxxx yyyyyy zzzzzz aaaaaa bbbbbb Value = 57 This is necessary because in a file there are written more lines which... (6 Replies)
Discussion started by: wenclu
6 Replies

5. Shell Programming and Scripting

how to copy the directory but not copy certain file

Hi experts cp bin root src /mnt but not copy bin/bigfile any help? ( I post this thread in the "redhat" forum wrongly, I don't know how to withdraw that question in that wrong forum) Thanks (6 Replies)
Discussion started by: yanglei_fage
6 Replies

6. UNIX for Dummies Questions & Answers

Copy the last part since the file has been updated

Input File1 constatntly running and growing in size. My Program Erorr ddmmyy hh:mm:ss My Program Error **Port 123 terminated **ID PIN 12345 Comamnd Successful Command Terminated Command Successful Command Terminated **My Program Erorr ddmmyy hh:mm:ss My Program Error **Port 345... (3 Replies)
Discussion started by: eurouno
3 Replies

7. Shell Programming and Scripting

Copy part of a variable

Hi, i was using a input file to get the last line of the file.But now i have stored the values from the file to a variable and want the last line from the variable . Slightly confused on how to extract that data from the variable. previous code, cat input.txt <TIME>00:15:48</TIME>... (2 Replies)
Discussion started by: Shellslave
2 Replies

8. Shell Programming and Scripting

Perl or Awk script to copy a part of text file.

Hi Gurus, I'm a total newbie to Perl and Awk scripting. Let me explain the scenario, there is a DB2 table with 5 columns and one of the column is a CLOB datatype containing XML. We need all the 4 columns but only a portion of string from the XML column. We decided to export DB2 table to a .del... (26 Replies)
Discussion started by: asandy1234
26 Replies

9. UNIX for Dummies Questions & Answers

Can I copy only part of my file to a new file?

Hi, I am looking for command to allow me only copying certain lines of records in my file to a new file. Can I do that? (3 Replies)
Discussion started by: whatisthis
3 Replies
Login or Register to Ask a Question